Skip to content

fix: send server logs as JSONRPC log notifications (Fixes #571) - #582

Open
Luca Zani (OverloadedTech) wants to merge 2 commits into
microsoft:mainfrom
OverloadedTech:fix/server-log-notifications
Open

Luca Zani (OverloadedTech) wants to merge 2 commits into
microsoft:mainfrom
OverloadedTech:fix/server-log-notifications

Conversation

@OverloadedTech

Copy link
Copy Markdown

Since #314 pet server uses the same stderr tracing setup as pet find, so warnings and errors go to stderr with ANSI colors instead of being sent as log notifications (docs/JSONRPC.md). The extension logs stderr as errors, hence the [error] [pet] ␛[33m WARN␛[0m lines in #571.

This adds a small tracing layer for server mode that sends each event as a log notification with its level. The filter is the same as before (warn by default, RUST_LOG to change it), and trace maps to debug like the old initialize_logger did. The CLI now only uses colors when stderr is a terminal.

The raw RPC test client skips log notifications in receive(), since a few existing tests trigger errors and would otherwise get the notification before the reply.

PET_TRACE_FORMAT=json no longer does anything in server mode. I couldn't find anything using it there, but I can keep a stderr layer for it if you rely on it.

Tested on macOS: the new tests fail on main and pass here, cargo test and scripts/rust-precommit.sh are clean, and I checked the server output and pet find 2> err.txt by hand. Haven't tried Windows or the extension.

Fixes #571

Since microsoft#314, `pet server` wrote tracing output to stderr with ANSI colors
instead of sending `log` notifications, so the Python Environments
extension showed every warning as an [error] line full of escape codes.
The CLI also kept the colors when stderr was redirected to a file.
@OverloadedTech

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

pet server logs warnings as ANSI-colored stderr, shown as errors

1 participant