Skip to content

Commit e9bffcb

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 efe4836 commit e9bffcb

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

Sources/SKLogging/SetGlobalLogFileHandler.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,18 @@ 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,
122126
logFileMaxBytes: logFileMaxBytes,
123127
logRotateCount: logRotateCount
124128
)
125129
} catch {
126-
fputs(
127-
"""
128-
Failed to write message to log file: \(error)
129-
\(message)
130-
131-
""",
132-
stderr
133-
)
130+
fputs("Failed to write message to log file: \(error)", stderr)
134131
}
135132
}
136133
}

0 commit comments

Comments
 (0)