Skip to content
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

Question: tracing_subscriber::fmt() in examples #423

Open
Schottkyc137 opened this issue Jun 30, 2024 · 1 comment
Open

Question: tracing_subscriber::fmt() in examples #423

Schottkyc137 opened this issue Jun 30, 2024 · 1 comment

Comments

@Schottkyc137
Copy link

In One of the example files where the language server communicates with a client using stdin and stdout, the logging framework is initialised using tracing_subscriber::fmt().init(). Is this best practice? Doesn't this mean that the language server interferes with the logging framework?
One of my projects produces a warning since a client sends a message that is not implemented and consequently causing the server to malfunction. The following is an excerpt from the error log:

[coc.nvim] Connection to server dts is erroring, Header must provide a Content-Length property.
{"\u001b[2m2024-06-30t17":"26:58.978499Z\u001b[0m \u001b[33m WARN\u001b[0m \u001b[2mtower_lsp\u001b[0m\u001b[2m:\u001b[0m Got a workspace/didChangeConfiguration notification, but it is not implemented\nContent-Leng
[coc.nvim] Connection to server dts is erroring, Header must provide a Content-Length property.
{"{\"jsonrpc\"":"\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"diagnostics\":[{\"code\":\"expected\",\"message\":\"Expected one of /dts-v1/, /memreserve/, /include/, /delete-node/, /omit-if-n
o-ref/, '/', reference\",\"range\":{\"end\":{\"character\":1,\"line\":0},\"start\":{\"character\":0,\"line\":0}},\"severity\":1,\"source\":\"ginko_ls\"}],\"uri\":\"file:///Users/lukasscheller/.local/share/nvim/site
/pack/x.dts\"}}\u001b[2m2024-06-30T17:26:58.984067Z\u001b[0m \u001b[32m INFO\u001b[0m \u001b[2mtower_lsp::service::layers\u001b[0m\u001b[2m:\u001b[0m shutdown request received, shutting down\nContent-Length: 38"}. 
Shutting down server.

Is there a reason why the tracing_subscriber::fmt().init() method is used (since it can interfere with the actual messages)? Is there a better methods?
Thanks for all replies!

@idealseal
Copy link

@Schottkyc137
Yes, you should be using stderr for logging.

tracing_subscriber::fmt().with_writer(std::io::stderr).init();

If you want to get rid of the ANSI escape codes, which most editors don't handle in there log capture, you should disable them, too.

tracing_subscriber::fmt().with_writer(std::io::stderr).with_ansi(false).init();

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

No branches or pull requests

2 participants