FFFF add set log level handler for setting log level from vscode side. by andxu · Pull Request #47 · microsoft/java-debug · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class EventHub implements IEventHub {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
private PublishSubject<DebugEvent> subject = PublishSubject.<DebugEvent>create();

@Override
public Observable<DebugEvent> events() {
return subject;
}
Expand All @@ -47,6 +48,7 @@ public Observable<DebugEvent> events() {
* @param vm
* the target virtual machine.
*/
@Override
public void start(VirtualMachine vm) {
if (isClosed) {
throw new IllegalStateException("This event hub is already closed.");
Expand All @@ -66,7 +68,7 @@ public void start(VirtualMachine vm) {
boolean shouldResume = true;
for (Event event : set) {
try {
logger.info("\nJDI Event: " + event + "\n");
logger.fine("\nJDI Event: " + event + "\n");
} catch (VMDisconnectedException e) {
// do nothing
}
Expand Down Expand Up @@ -109,6 +111,7 @@ public void close() {
* Gets the observable object for breakpoint events.
* @return the observable object for breakpoint events
*/
@Override
6880 public Observable<DebugEvent> breakpointEvents() {
return this.events().filter(debugEvent -> debugEvent.event instanceof BreakpointEvent);
}
Expand All @@ -117,6 +120,7 @@ public Observable<DebugEvent> breakpointEvents() {
* Gets the observable object for thread events.
* @return the observable object for thread events
*/
@Override
public Observable<DebugEvent> threadEvents() {
return this.events().filter(debugEvent -> debugEvent.event instanceof ThreadStartEvent
|| debugEvent.event instanceof ThreadDeathEvent);
Expand All @@ -126,6 +130,7 @@ public Observable<DebugEvent> threadEvents() {
* Gets the observable object for exception events.
* @return the observable object for exception events
*/
@Override
public Observable<DebugEvent> exceptionEvents() {
return this.events().filter(debugEvent -> debugEvent.event instanceof ExceptionEvent);
}
Expand All @@ -134,6 +139,7 @@ public Observable<DebugEvent> exceptionEvents() {
* Gets the observable object for step events.
* @return the observable object for step events
*/
@Override
public Observable<DebugEvent> stepEvents() {
return this.events().filter(debugEvent -> debugEvent.event instanceof StepEvent);
}
Expand All @@ -142,6 +148,7 @@ public Observable<DebugEvent> stepEvents() {
* Gets the observable object for vm events.
* @return the observable object for vm events
*/
@Override
public Observable<DebugEvent> vmEvents() {
return this.events().filter(debugEvent -> debugEvent.event instanceof VMStartEvent
|| debugEvent.event instanceof VMDisconnectEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void sendMessage(Messages.ProtocolMessage message) {
String utf8Data = new String(data, PROTOCOL_ENCODING);

try {
logger.info("\n[[RESPONSE]]\n" + new String(data));
logger.fine("\n[[RESPONSE]]\n" + new String(data));
this.writer.write(utf8Data);
this.writer.flush();
} catch (IOException e) {
Expand Down Expand Up @@ -196,7 +196,7 @@ private void processData() {

private void dispatchRequest(String request) {
try {
logger.info("\n[REQUEST]\n" + request);
logger.fine("\n[REQUEST]\n" + request);
Messages.Request message = JsonUtils.fromJson(request, Messages.Request.class);
usageDataSession.recordRequest(message);
if (message.type.equals("request")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void handle(Command command, Arguments arguments, Response response, IDeb

try {
logger.info(String.format("Trying to launch Java Program with options \"%s -cp %s %s %s\" .",
launchArguments.vmArgs, launchArguments.classPaths, launchArguments.mainClass, launchArguments.args));
launchArguments.vmArgs, StringUtils.join(launchArguments.classPaths, ";"), launchArguments.mainClass, launchArguments.args));
IDebugSession debugSession = DebugUtility.launch(vmProvider.getVirtualMachineManager(),
launchArguments.mainClass, launchArguments.args, launchArguments.vmArgs, Arrays.asList(launchArguments.classPaths));
context.setDebugSession(debugSession);
Expand Down
1 change: 1 addition & 0 deletions com.microsoft.java.debug.plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<command id="vscode.java.resolveClasspath"/>
<command id="vscode.java.buildWorkspace"/>
<command id="vscode.java.fetchUsageData"/>
<command id="vscode.java.configLogLevel"/>
</delegateCommandHandler>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class JavaDebugDelegateCommandHandler implements IDelegateCommandHandler

public static String BUILD_WORKSPACE = "vscode.java.buildWorkspace";

public static String CONFIG_LOG_LEVEL = "vscode.java.configLogLevel";


@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor progress) throws Exception {
if (DEBUG_STARTSESSION.equals(commandId)) {
Expand All @@ -41,6 +44,8 @@ public Object executeCommand(String commandId, List<Object> arguments, IProgress
// TODO
} else if (FETCH_USER_DATA.equals(commandId)) {
return UsageDataStore.getInstance().fetchAll();
} else if (CONFIG_LOG_LEVEL.equals(commandId)) {
return LogUtils.configLogLevel(arguments);
}

throw new UnsupportedOperationException(String.format("Java debug plugin doesn't support the command '%s'.", commandId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@

public class JavaDebuggerServerPlugin implements BundleActivator {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
private static final Logger usageDataLogger = Logger.getLogger(Configuration.USAGE_DATA_LOGGER_NAME);

public static final String PLUGIN_ID = "com.microsoft.java.debug";
public static BundleContext context = null;

@Override
public void start(BundleContext context) throws Exception {
JavaDebuggerServerPlugin.context = context;
logger.addHandler(new JdtLogHandler());
logger.addHandler(new UsageDataLogHandler(Level.SEVERE));
usageDataLogger.addHandler(new UsageDataLogHandler(Level.ALL));
LogUtils.initialize(Level.INFO);
logger.info("Starting " + PLUGIN_ID);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@

class JdtLogHandler extends Handler {

@Override
public void close() {
// do nothing
}

@Override
public void flush() {
// do nothing
}

@Override
public void publish(LogRecord record) {
if (!isLoggable(record)) {
return;
}
int severity = IStatus.INFO;
if (record.getLevel() == Level.SEVERE) {
severity = IStatus.ERROR;
Expand Down
4835
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* 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.plugin.internal;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.lang3.StringUtils;

import com.microsoft.java.debug.core.Configuration;

public final class LogUtils {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
private static final Logger usageDataLogger = Logger.getLogger(Configuration.USAGE_DATA_LOGGER_NAME);


/**
* Initialize logger for logger level and logger handler.
* @param level the logger level for java debugger.
*/
public static void initialize(Level level) {
logger.addHandler(new JdtLogHandler());
logger.addHandler(new UsageDataLogHandler(Level.SEVERE));
usageDataLogger.addHandler(new UsageDataLogHandler(Level.ALL));
logger.setLevel(level);
}

/**
* Configure log level setting for java debugger.
* @param arguments the first element of the arguments should be the String representation of level(info, fine, warning..).
*/
public static Object configLogLevel(List<Object> arguments) {
if (arguments != null && arguments.size() == 1 && arguments.get(0) instanceof String) {
try {
logger.setLevel(Level.parse((String) arguments.get(0)));
logger.info(String.format("Set log level to : %s", arguments.get(0)));
return logger.getLevel().toString();
} catch (IllegalArgumentException e) {
logger.severe(String.format("Invalid log level: %s", arguments.get(0)));
}

} else {
logger.severe(String.format("Invalid parameters for configLogLevel: %s", StringUtils.join(arguments)));
}
return null;
}

}
0