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

CapturedOutput is empty when using Log4J2 StatusLogger #43578

Closed
nosan opened this issue Dec 19, 2024 · 3 comments
Closed

CapturedOutput is empty when using Log4J2 StatusLogger #43578

nosan opened this issue Dec 19, 2024 · 3 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@nosan
Copy link
Contributor

nosan commented Dec 19, 2024

While working on #43575 I noticed that Log4j2 Smoke Tests does not contain a test to verify that DefaultErrorHandler prints an error into the console if StructuredLogLayout throws an Exception.

I added a test to check DefaultErrorHandler prints errors but unfortunately, it did not work since Log42J StatusLogger keeps the reference to the outdated PrintStreamCapture.

Reproducer: main...nosan:spring-boot:log4j2-status-logger

If you run a single test shouldCaptureCustomizerError in SampleLog4j2StructuredLoggingApplicationTests everything will be fine, but if you run all tests in SampleLog4j2StructuredLoggingApplicationTests, the CapturedOutput will be empty and shouldCaptureCustomizerError test will fail.

Possible fix main...nosan:spring-boot:log4j2-status-logger-fix but I am not sure this is the right way.

@nosan nosan changed the title CapturedOutput is empty when using Log42J StatusLogger CapturedOutput is empty when using Log4J2 StatusLogger Dec 19, 2024
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 19, 2024
@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label Dec 20, 2024
@philwebb philwebb self-assigned this Jan 6, 2025
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Jan 7, 2025
@philwebb philwebb modified the milestones: 3.3.8, 3.4.2 Jan 7, 2025
@philwebb
Copy link
Member

philwebb commented Jan 7, 2025

Thanks @nosan, I've taken your test and a slightly different fix. I hope that's OK. Let me know if you see any potential issues.

@nosan
Copy link
Contributor Author

nosan commented Jan 7, 2025

Thanks, @philwebb.
I am worried about what happens if someone replaces fallbackListener with their own PrintStream. In that scenario, Log4J2LoggingSystem would overwrite it with System.out.

Maybe reset fallbackListener's stream should be applied only in the smoke-test.

@philwebb
Copy link
Member

philwebb commented Jan 7, 2025

I did a bit of manual testing for that and I think Log4J2LoggingSystem sets the stream before the configuration is applied. In other words, I think it sets the stream to System.out and then the user configuration kicks in and changes it to whatever they want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants