Skip to content

Commit 37d21d8

Browse files
committed
Log to stderr as well as the log file, on non-Darwin platforms
This is consistent with other LSP servers, and makes debugging sourcekit-lsp easier.
1 parent 8a908f2 commit 37d21d8

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Sources/SKLogging/NonDarwinLogging.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ package struct NonDarwinLogger: Sendable {
346346
// sourcekitd response). 10.000 characters was chosen because it seems to fit the result of most sourcekitd
347347
// responses that are not generated interface or global completion results (which are a lot bigger).
348348
var message = message().value.string(for: self.privacyLevel)
349+
349350
if message.utf8.count > 10_000 {
350351
// Check for UTF-8 byte length first because that's faster since it doesn't need to count UTF-8 characters.
351352
// Truncate using `.prefix` to avoid cutting of in the middle of a UTF-8 multi-byte character.

Sources/SKLogging/SetGlobalLogFileHandler.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ private func logToFile(message: String, logDirectory: URL, logFileMaxBytes: Int,
116116
private func setUpGlobalLogFileHandlerImpl(logFileDirectory: URL, logFileMaxBytes: Int, logRotateCount: Int) {
117117
logHandler = { @LogHandlerActor message in
118118
do {
119+
// In addition to writing to the log file, also log to stderr, so LSP output is visible in the editor
120+
// (e.g. VS Code's Output panel).
121+
fputs(message + "\n", stderr)
122+
119123
try logToFile(
120124
message: message,
121125
logDirectory: logFileDirectory,

0 commit comments

Comments
 (0)