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

Log4j2: add option to fill code attributes #12592

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Nov 8, 2024

Resolves #12540

@laurit laurit requested a review from a team as a code owner November 8, 2024 10:44
@trask
Copy link
Member

trask commented Nov 8, 2024

cc @jeanbisutti in case you have a chance to review

}
if (stackTraceClass == null) {
try {
stackTraceClass = Class.forName("org.apache.logging.log4j.core.impl.Log4jLogEvent");
Copy link
Member

@jeanbisutti jeanbisutti Nov 8, 2024

Choose a reason for hiding this comment

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

The stack trace class is not the same following the Log4j version? If so, could you please add comments to explain this?

It's perhaps the intent of the comment added at line 121? If so, could you please move this comment around the line 124?

StackTraceElement source = sourceSupplier.get();
if (source != null) {
String fileName = source.getFileName();
if (fileName != null) {
Copy link
Member

Choose a reason for hiding this comment

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

(optional)

Suggested change
if (fileName != null) {
// file name can be null from the StackTraceElement Javadoc
if (fileName != null) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is copy-pasted from the logback instrumentation. Apparently you are the author of it.

Class<?> testClass, String methodName, AttributeAssertion... assertions) {
String selector = System.getProperty("Log4j2.contextSelector");
boolean async = selector != null && selector.endsWith("AsyncLoggerContextSelector");
if (async) {
Copy link
Member

Choose a reason for hiding this comment

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

I have not found the test using an asynch appender. Could you please give me a pointer?

The Readme should perhaps explain something about the asynch appenders?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

val testAsync by registering(Test::class) {
jvmArgs("-DLog4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector")
}
check {
dependsOn(testAsync)
}

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.

MDC attributes not captured with spring boot application using log4j.
3 participants