Skip to content

StatusLogger: Write to stderr by default #3666

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

Merged
merged 1 commit into from
May 16, 2025
Merged

Conversation

rschmitt
Copy link
Contributor

StatusLogger messages used to be written to stderr by default. Since 2.23.0, they are being written to stdout. This is a significant regression. As a rule, stderr is for humans, and stdout is for programs. The pipe operator redirects stdout by default, and a CLI utility can have its output corrupted because Log4j2 emitted a status message to stdout. For example, consider a program that emits JSON and has its output piped to jq: after upgrading to Log4j 2.23.0 or later, this program will cease to work correctly unless the StatusLogger is reconfigured to not emit anything, or is explicitly configured to write to stderr.

This regression can be fixed by calling the two-parameter constructor variant of StatusConsoleListener from StatusLogger. A simple test case has been added that captures stdout/stderr and ensures that the default StatusLogger is not emitting anything to stdout.

Fixes #3665.

@ppkarwasz
Copy link
Contributor

@rschmitt,

Looks good thanks! 💯

Commits in this repo must have verified signatures. Can you add a GPG key to your GitHub account and resign the commit with that key?

git commit --amend -S

Copy link

github-actions bot commented May 15, 2025

Job Requested goals Build Tool Version Build Outcome Build Scan®
build-macos-latest clean install 3.9.8 Build Scan PUBLISHED
build-ubuntu-latest clean install 3.9.8 Build Scan PUBLISHED
build-windows-latest clean install 3.9.8 Build Scan PUBLISHED
Generated by gradle/develocity-actions

`StatusLogger` messages used to be written to stderr by default. Since
2.23.0, they are being written to stdout. This is a significant
regression. As a rule, stderr is for humans, and stdout is for programs.
The pipe operator redirects stdout by default, and a CLI utility can
have its output corrupted because Log4j2 emitted a status message to
stdout. For example, consider a program that emits JSON and has its
output piped to `jq`: after upgrading to Log4j 2.23.0 or later, this
program will cease to work correctly unless the StatusLogger is
reconfigured to not emit anything, or is explicitly configured to write
to stderr.

This regression can be fixed by calling the two-parameter constructor
variant of `StatusConsoleListener` from `StatusLogger`. A simple test
case has been added that captures stdout/stderr and ensures that the
default `StatusLogger` is not emitting anything to stdout.

Fixes apache#3665.
@ppkarwasz
Copy link
Contributor

Thanks!

@ppkarwasz ppkarwasz merged commit ac34697 into apache:2.x May 16, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from To triage to Done in Log4j bug tracker May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Regression: StatusLogger has switched from stderr to stdout by default
2 participants