Skip to content

fix(logger): write $ALLOW_CONSOLE logs to stderr - #569

Open
NopeCharon wants to merge 1 commit into
neovim:masterfrom
NopeCharon:logger-stderr
Open

NopeCharon wants to merge 1 commit into
neovim:masterfrom
NopeCharon:logger-stderr

Conversation

@NopeCharon

Copy link
Copy Markdown

Problem:
With $ALLOW_CONSOLE set, the winston Console transport writes logs to
stdout. When stdio is the RPC channel (e.g. remote plugins started by
Nvim), the log lines are read as invalid msgpack-RPC messages, which
breaks the channel and kills the host. This reproduces with
ALLOW_CONSOLE=1 npm test in packages/integration-tests: the remote
plugin commands/functions are never registered, so 3 tests fail
(E492: Not an editor command: JSHostTestCmd, E117: Unknown function: Func).

Solution:

  • Route all log levels of the Console transport to stderr via
    stderrLevels. stderr is not part of the RPC channel (Nvim collects a
    job's stderr separately), so $ALLOW_CONSOLE is now safe with stdio RPC.
  • Update README and CHANGELOG.
  • Add a test that spawns a process with ALLOW_CONSOLE=1 and checks that
    logs (including the patched console.log) go to stderr and nothing to stdout.

With this change the integration tests also pass with ALLOW_CONSOLE=1.

Fixes #343

Problem:
With `$ALLOW_CONSOLE` set, the winston Console transport writes logs to
stdout. When stdio is the RPC channel (e.g. remote plugins started by
Nvim), the log lines are interpreted as invalid msgpack-RPC messages,
which breaks the channel and kills the host. Running the integration
tests with `ALLOW_CONSOLE=1` reproduces it: the remote plugin commands
and functions are never registered.

Solution:
Route all log levels of the Console transport to stderr via
`stderrLevels`. stderr is not part of the RPC channel (Nvim collects a
job's stderr separately), so `$ALLOW_CONSOLE` is now safe to use with
stdio RPC. Update the README accordingly and add a test that checks
that nothing is written to stdout.

Fixes neovim#343

This branch has not been deployed

No deployments
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.

logging: ALLOW_CONSOLE should write to stderr instead of stdout, to avoid breaking stdio RPC channel

1 participant