Repository navigation
add log for catch (Exception) clause #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
18cb0b5
add log for catch (Exception) clause because we want why there is an …
andxu b7652a5
fix typo
andxu c92abcc
refactor the way to record log.
andxu e06e6ba
refactor the way to record log.
andxu 55109c6
Merge remote-tracking branch 'origin/master' into andy_launch_attach_log
andxu cac2a4c
refactor the way to record log.
andxu b4c8af5
Merge branch 'master' into andy_launch_attach_log
andxu 116c8a1
Merge remote-tracking branch 'origin' into andy_launch_attach_log
andxu 5cecac1
add usage data collection in Log.
andxu 6bec00e
Merge remote-tracking branch 'origin' into andy_launch_attach_log
andxu ce219e8
add Log in new added classes.
andxu 665ec38
move endSession to the end of start method to avoid missing ending me…
andxu d095183
Merge branch 'master' into andy_launch_attach_log
andxu 9ed5d5d
Merge branch 'master' into andy_launch_attach_log
andxu 20f3fef
Update LaunchRequestHandler.java
andxu dfda841
Fix issue after merging code
andxu c70554a
Fix issue after merging code
andxu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/Log.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2017 Microsoft Corporation and others. | ||
| * All rights reserved. This program and the accompanying materials | ||
| * are made available under the terms of the Eclipse Public License v1.0 | ||
| * which accompanies this distribution, and is available at | ||
| * http://www.eclipse.org/legal/epl-v10.html | ||
| * | ||
| * Contributors: | ||
| * Microsoft Corporation - initial API and implementation | ||
| *******************************************************************************/ | ||
|
|
||
| package com.microsoft.java.debug.core; | ||
|
|
||
| import java.util.logging.Handler; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import com.microsoft.java.debug.core.adapter.Messages; | ||
| import com.sun.jdi.event.Event; | ||
|
|
||
| /** | ||
| * This helper class provides static methods for a default instance of <code>java.util.logging.Logger</code>,a simple code like | ||
| * <code>Log.info("Sample trace: %d", 10)</code> is able to replace <code>logger.info(String.format("Sample trace: %d", 10))</code>. | ||
| * Using a very short name to better code fitness. | ||
| */ | ||
| public final class Log { | ||
| private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME); | ||
|
|
||
| /** | ||
| * Log an ERROR message. | ||
| * | ||
| * @param ex The exception object | ||
| * @param message The string message | ||
| * @param arguments Arguments referenced by the format specifiers in the message | ||
| */ | ||
| public static void error(Exception ex, String message, Object... arguments) { | ||
| logger.log(Level.SEVERE, String.format(message, arguments), ex); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Log an ERROR message. | ||
| * | ||
| * @param message The string message | ||
| * @param arguments Arguments referenced by the format specifiers in the message | ||
| */ | ||
| public static void error(String message, Object... arguments) { | ||
| logger.severe(String.format(message, arguments)); | ||
| } | ||
|
|
||
| /** | ||
| * Log a INFO message. | ||
| * | ||
| * @param message The string message | ||
| * @param arguments Arguments referenced by the format specifiers in the message | ||
| * string. | ||
| */ | ||
| public static void info(String message, Object... arguments) { | ||
| logger.info(String.format(message, arguments)); | ||
| } | ||
|
|
||
| /** | ||
| * Log a WARN message. | ||
| * | ||
| * @param message The string message | ||
| * @param arguments Arguments referenced by the format specifiers in the message | ||
| */ | ||
| public static void warn(String message, Object... arguments) { | ||
| logger.warning(String.format(message, arguments)); | ||
| } | ||
|
|
||
| /** | ||
| * Log a DEBUG message. | ||
| * | ||
| * @param message The string message | ||
| * @param arguments Arguments referenced by the format specifiers in the message | ||
| */ | ||
| public static void debug(String message, Object... arguments) { | ||
| logger.fine(String.format(message, arguments)); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Set the log level specifying which message levels will be | ||
| * logged by this logger. Message levels lower than this | ||
| * value will be discarded. The level value Level.OFF | ||
| * can be used to turn off logging. | ||
| * | ||
| * @param newLevel the new value for the log level (may be null) | ||
| */ | ||
| public static void setLevel(Level newLevel) { | ||
| logger.setLevel(newLevel); | ||
| } | ||
|
|
||
| /** | ||
| * Add a log Handler to receive logging messages. | ||
| * @param handler a logging Handler | ||
| */ | ||
| public static void addHandler(Handler handler) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any API corresponding to remove the handler?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
| logger.addHandler(handler); | ||
| } | ||
|
|
||
| /** | ||
| * Remove a log Handler. | ||
| * Returns silently if the given Handler is not found or is null | ||
| * | ||
| * @param handler a logging Handler | ||
| */ | ||
| public static void removeHandler(Handler handler) throws SecurityException { | ||
| logger.removeHandler(handler); | ||
| } | ||
|
|
||
| /** | ||
| * Record a JDI event. | ||
| * @param event the JDI event. | ||
| */ | ||
| public static void traceEvent(Event event) { | ||
| UsageDataSession.recordEvent(event); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Begin an user data collection session to record events, requests and errors. | ||
| * | ||
| * @return a new user data collection session | ||
| */ | ||
| public static UsageDataSession beginSession() { | ||
| UsageDataSession session = new UsageDataSession(); | ||
| session.reportStart(); | ||
| return session; | ||
| } | ||
|
|
||
| /** | ||
| * Record the request from VSCode side. | ||
| * | ||
| * @param session user data collection session | ||
| * @param request from VSCode. | ||
| */ | ||
| public static void traceRequest(UsageDataSession session, Messages.Request request) { | ||
| if (session != null && request != null) { | ||
| session.recordRequest(request); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Record the response sends to VSCode. | ||
| * | ||
| * @param session user data collection session | ||
| * @param response to VSCode. | ||
| */ | ||
| public static void traceResponse(UsageDataSession session, Messages.Response response) { | ||
| if (session != null && response != null) { | ||
| session.recordResponse(response); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * End an user data collection session, and report the usage datas. | ||
| * | ||
| * @param session user data collection session | ||
| */ | ||
| public static void endSession(UsageDataSession session) { | ||
| if (session != null) { | ||
| session.reportStop(); | ||
| session.submitUsageData(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private Log() { | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to wrap around the JDK logger? I didn't see much value added. Am I missing anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is mainly to focus on simplifying the logging code to better code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trace user data is also include in Log.java, Log will be the only class need to record logs and user datas.