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

Conversation

Wilfred
Copy link
Contributor

@Wilfred Wilfred commented May 13, 2025

This is consistent with other LSP servers, and makes debugging sourcekit-lsp easier.

This was initially discussed in #2116. Let me know if you think we should log to stderr on macOS too.

@Wilfred Wilfred requested a review from ahoppen as a code owner May 13, 2025 16:07
Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do log to stderr until we set up the global log file handlers using setUpGlobalLogFileHandler. We should also log to stderr from there. With the current implementation, we would log every message twice if setting up the global log file handlers failed (once from the log handler and then once again from your fputs call).

@Wilfred
Copy link
Contributor Author

Wilfred commented May 16, 2025

Gotcha, presumably something like this is better?

This is consistent with other LSP servers, and makes debugging
sourcekit-lsp easier.
@bnbarham
Copy link
Contributor

@swift-ci please test

Comment on lines +119 to +122
// 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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost LGTM :). But now that we're printing this to stderr as well, I think we can remove the \(message) from the fputs below when the write to the log fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants