Skip to content
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

improvement: Send debug logs to BSP client #2105

Merged
merged 2 commits into from
Jul 7, 2023
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
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