google / google/nsjail

Allow a separate log level for stderr when --log/--log_fd points elsewhere

Open
#301 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
4.1k
Forks
371
Avg merge
4d 7h
Merged PRs (30d)
7

Description

# Problem

nsjail currently has a single log sink and severity threshold. `-v`, `-q`, and `-Q` control which messages are emitted, while `--log` and `--log_fd` move the entire log stream to another destination.

This makes it difficult for callers with two different logging audiences. For example, a service running nsjail as a child process may want to:
- retain verbose nsjail diagnostics in an internal log; and
- expose only fatal nsjail errors on stderr, which may be surfaced to the end user.

Currently, redirecting nsjail's logs to a file or dedicated fd also removes fatal messages from stderr. Keeping stderr as the log destination instead exposes all enabled nsjail diagnostics there.

This can be implemented externally by intercepting and filtering the log stream, but doing so requires callers to parse nsjail's textual log format and maintain an additional forwarding layer.

# Proposal

Add an optional argument:
```
--log_stderr_level=debug|info|warning|error|fatal
```

When the primary log sink is not stderr, messages at or above this level would also be written to stderr.

If the primary sink is already stderr, the option would have no additional effect or duplicate messages.

`--log_stderr_level` is independent of `-v`/`-q`/`-Q`. Each sink applies its own level. The primary sink emits messages at or above the level set by `-v`/`-q`/`-Q`, and stderr emits messages at or above `--log_stderr_level`.

# Status

I have a working implementation locally and can send a PR if this approach sounds useful, or adjust the design if a different interface would fit nsjail better.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the existing --log and --log_fd option handling and the single log sink. Verify how -v, -q, and -Q set the primary threshold, then implement the separate stderr threshold described in the proposal. Done means qualifying messages reach stderr only when the primary sink is elsewhere, without duplicates when stderr is already the sink.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.