Skip to content

Commit

Permalink
Merge pull request #2105 from tgodzik/print-verbose
Browse files Browse the repository at this point in the history
improvement: Send debug logs to BSP client
  • Loading branch information
tgodzik committed Jul 7, 2023
2 parents 71b0409 + eed9bf0 commit 6431f46
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
25 changes: 23 additions & 2 deletions frontend/src/main/scala/bloop/logging/BspServerLogger.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,32 @@ 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)

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(
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/test/scala/bloop/bsp/BspCompileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/test/scala/bloop/bsp/BspConnectionSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"""|
Expand Down

0 comments on commit 6431f46

Please sign in to comment.