Skip to content

test(log4j2): Add initial test suite covering plugin registration#615

Open
rschmitt wants to merge 1 commit into
aws:mainfrom
rschmitt:add-tests
Open

test(log4j2): Add initial test suite covering plugin registration#615
rschmitt wants to merge 1 commit into
aws:mainfrom
rschmitt:add-tests

Conversation

@rschmitt
Copy link
Copy Markdown

This package previously had no tests and no JUnit dependency. Add JUnit Jupiter, the surefire plugin, and an initial test class that exercises the full plugin resolution path end-to-end: a log4j2.xml on the test classpath, a real LogManager-issued logger, and stdout capture (LambdaAppender writes through LambdaRuntime.getLogger() to System.out).

The TEXT test routes the root logger through LambdaTextFormat with a deterministic PatternLayout and asserts each level appears. The JSON test adds a second LambdaAppender with format="JSON" backed by JsonTemplateLayout + LambdaLayout.json, attached via additivity=false to a "json-test" logger, and asserts the messages show up JSON-encoded.

Add log4j-layout-template-json at test scope so the JSON path can resolve at test time. Users are still expected to bring their own copy at runtime (peer-dependency model, like PatternLayout); the published artifact's dependency surface is unchanged.

The tests succeed on Java 8 and fail on Java 25, because annotation processors are not run by default on Java 25, Log4j2Plugins.dat is not generated for our plugins, and both tests surface the resulting CLASS_NOT_FOUND from the log4j status logger.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

This package previously had no tests and no JUnit dependency. Add
JUnit Jupiter, the surefire plugin, and an initial test class that
exercises the full plugin resolution path end-to-end: a log4j2.xml
on the test classpath, a real LogManager-issued logger, and stdout
capture (LambdaAppender writes through LambdaRuntime.getLogger() to
System.out).

The TEXT test routes the root logger through LambdaTextFormat with a
deterministic PatternLayout and asserts each level appears. The JSON
test adds a second LambdaAppender with format="JSON" backed by
JsonTemplateLayout + LambdaLayout.json, attached via additivity=false
to a "json-test" logger, and asserts the messages show up
JSON-encoded.

Add log4j-layout-template-json at test scope so the JSON path can
resolve at test time. Users are still expected to bring their own
copy at runtime (peer-dependency model, like PatternLayout); the
published artifact's dependency surface is unchanged.

The tests succeed on Java 8 and fail on Java 25, because annotation
processors are not run by default on Java 25, Log4j2Plugins.dat is
not generated for our plugins, and both tests surface the resulting
CLASS_NOT_FOUND from the log4j status logger.
@darklight3it
Copy link
Copy Markdown
Contributor

This should be merged before #616

that is needed to prevent situation like #612

Copy link
Copy Markdown
Contributor

@darklight3it darklight3it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀 Thanks for the help!

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.

2 participants