From a0b631319ba3233e5af833d84a25adaca98fceec Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Thu, 6 Jul 2023 16:24:59 +0200 Subject: [PATCH 1/2] improvement: Send debug logs to BSP client Previously, we would only print the logs when using Bloop from CLI --- .../src/main/scala/bloop/logging/BspServerLogger.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/main/scala/bloop/logging/BspServerLogger.scala b/frontend/src/main/scala/bloop/logging/BspServerLogger.scala index 82ec4272be..a587c7738d 100644 --- a/frontend/src/main/scala/bloop/logging/BspServerLogger.scala +++ b/frontend/src/main/scala/bloop/logging/BspServerLogger.scala @@ -53,7 +53,15 @@ final class BspServerLogger private ( override def ansiCodesSupported: Boolean = ansiSupported || underlying.ansiCodesSupported() - override private[logging] def printDebug(msg: String): Unit = underlying.printDebug(msg) + override private[logging] def printDebug(msg: String): Unit = { + if (isVerbose) + client.notify( + Build.logMessage, + bsp.LogMessageParams(bsp.MessageType.Log, None, originId, msg) + ) + underlying.printDebug(msg) + + } override def debug(msg: String)(implicit ctx: DebugFilter): Unit = if (debugFilter.isEnabledFor(ctx)) printDebug(msg) From eed9bf0d32a741a02f554186b1b2dcb3f78e9d3c Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Fri, 7 Jul 2023 14:49:37 +0200 Subject: [PATCH 2/2] improvement: Fix tests and also send trace messages --- .../scala/bloop/logging/BspServerLogger.scala | 15 ++++++++++++++- .../src/test/scala/bloop/bsp/BspCompileSpec.scala | 4 +++- .../test/scala/bloop/bsp/BspConnectionSpec.scala | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/frontend/src/main/scala/bloop/logging/BspServerLogger.scala b/frontend/src/main/scala/bloop/logging/BspServerLogger.scala index a587c7738d..f7d92b9d9a 100644 --- a/frontend/src/main/scala/bloop/logging/BspServerLogger.scala +++ b/frontend/src/main/scala/bloop/logging/BspServerLogger.scala @@ -65,7 +65,20 @@ final class BspServerLogger private ( override def debug(msg: String)(implicit ctx: DebugFilter): Unit = if (debugFilter.isEnabledFor(ctx)) printDebug(msg) - override def trace(t: Throwable): Unit = underlying.trace(t) + override def trace(t: Throwable): Unit = { + if (isVerbose) { + def msg(t: Throwable): String = { + val base = t.getMessage() + "\n" + t.getStackTrace().mkString("\n\t") + if (t.getCause() == null) base + else base + "\nCaused by: " + msg(t.getCause()) + } + client.notify( + Build.logMessage, + bsp.LogMessageParams(bsp.MessageType.Log, None, originId, msg(t)) + ) + } + underlying.trace(t) + } override def error(msg: String): Unit = { client.notify( diff --git a/frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala b/frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala index 111b3d787d..acdb7f7bbc 100644 --- a/frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala +++ b/frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala @@ -36,7 +36,9 @@ class BspCompileSpec( assertExitStatus(state, ExitStatus.Ok) } } - val contentLogs = logger.debugs.flatMap(_.split("\n")).filter(_.startsWith(" --> content:")) + val contentLogs = logger.debugs + .flatMap(_.split("\n")) + .filter(msg => msg.startsWith(" --> content:") && !msg.contains("logMessage")) val allButInitializeRequest = contentLogs.filterNot(_.contains("""build/initialize"""")) // Filter out the initialize request that contains platform-specific details assertNoDiff( diff --git a/frontend/src/test/scala/bloop/bsp/BspConnectionSpec.scala b/frontend/src/test/scala/bloop/bsp/BspConnectionSpec.scala index a967348d7a..47b22a41e3 100644 --- a/frontend/src/test/scala/bloop/bsp/BspConnectionSpec.scala +++ b/frontend/src/test/scala/bloop/bsp/BspConnectionSpec.scala @@ -90,7 +90,9 @@ class BspConnectionSpec( def checkConnectionIsInitialized(logger: RecordingLogger): Unit = { val contentLogs = logger.debugs.flatMap(_.split("\n")).filter(_.startsWith(" --> content:")) // Filter out the initialize request that contains platform-specific details - val allButInitializeRequest = contentLogs.filterNot(_.contains("""build/initialize"""")) + val allButInitializeRequest = contentLogs.filterNot(msg => + msg.contains("""build/initialize"""") || msg.contains("logMessage") + ) assertNoDiff( allButInitializeRequest.mkString(lineSeparator), s"""|