From e9bffcbd7e9a11dd6fde342fa24ec191c50269d7 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Tue, 13 May 2025 16:02:36 +0100 Subject: [PATCH] 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. --- Sources/SKLogging/SetGlobalLogFileHandler.swift | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Sources/SKLogging/SetGlobalLogFileHandler.swift b/Sources/SKLogging/SetGlobalLogFileHandler.swift index 0a15a02a3..1be1c67e3 100644 --- a/Sources/SKLogging/SetGlobalLogFileHandler.swift +++ b/Sources/SKLogging/SetGlobalLogFileHandler.swift @@ -116,6 +116,10 @@ private func logToFile(message: String, logDirectory: URL, logFileMaxBytes: Int, private func setUpGlobalLogFileHandlerImpl(logFileDirectory: URL, logFileMaxBytes: Int, logRotateCount: Int) { logHandler = { @LogHandlerActor message in do { + // In addition to writing to the log file, also log to stderr, so LSP output is visible in the editor + // (e.g. VS Code's Output panel). + fputs(message + "\n", stderr) + try logToFile( message: message, logDirectory: logFileDirectory, @@ -123,14 +127,7 @@ private func setUpGlobalLogFileHandlerImpl(logFileDirectory: URL, logFileMaxByte logRotateCount: logRotateCount ) } catch { - fputs( - """ - Failed to write message to log file: \(error) - \(message) - - """, - stderr - ) + fputs("Failed to write message to log file: \(error)", stderr) } } }