Skip to content

Commit 798d259

Browse files
authored
Send logpoint messages to the debug console (microsoft#402)
* Send logpoint messages as protocol events Instead of printing them to `System.out` of the process being debugged. This should be paired with a change in vscode-java-debug to receive the message and send it to the vscode debug console.
1 parent 7f6f76b commit 798d259

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

com.microsoft.java.debug.core/src/main/java/com/microsoft/java/debug/core/adapter/handler/SetBreakpointsRequestHandler.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.sun.jdi.BooleanValue;
4545
import com.sun.jdi.Field;
4646
import com.sun.jdi.ObjectReference;
47+
import com.sun.jdi.StringReference;
4748
import com.sun.jdi.ReferenceType;
4849
import com.sun.jdi.ThreadReference;
4950
import com.sun.jdi.Value;
@@ -222,6 +223,12 @@ public static boolean handleEvaluationResult(IDebugAdapterContext context, Threa
222223
context.getProtocolServer().sendEvent(new Events.UserNotificationEvent(
223224
Events.UserNotificationEvent.NotificationType.ERROR,
224225
String.format("[Logpoint] Log message '%s' error: %s", breakpoint.getLogMessage(), ex.getMessage())));
226+
} else if (value != null) {
227+
if (value instanceof StringReference) {
228+
String message = ((StringReference) value).value();
229+
context.getProtocolServer().sendEvent(Events.OutputEvent.createConsoleOutput(
230+
message + System.lineSeparator()));
231+
}
225232
}
226233
return true;
227234
} else {

com.microsoft.java.debug.plugin/src/main/java/com/microsoft/java/debug/plugin/internal/eval/JdtEvaluationProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ private String logMessageToExpression(String logMessage) {
226226
}
227227

228228
if (arguments.size() > 0) {
229-
return "System.out.println(String.format(\"" + format + "\"," + String.join(",", arguments) + "))";
229+
return "String.format(\"" + format + "\"," + String.join(",", arguments) + ")";
230230
} else {
231-
return "System.out.println(\"" + format + "\")";
231+
return "\"" + format + "\"";
232232
}
233233
}
234234

0 commit comments

Comments
 (0)