Skip to content

Log to stderr as well as the log file, on non-Darwin platforms #2155

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 5 additions & 8 deletions Sources/SKLogging/SetGlobalLogFileHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,18 @@ 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,
logFileMaxBytes: logFileMaxBytes,
logRotateCount: logRotateCount
)
} catch {
fputs(
"""
Failed to write message to log file: \(error)
\(message)

""",
stderr
)
fputs("Failed to write message to log file: \(error)", stderr)
}
}
}
Expand Down