ppkarwasz commented on issue #3257: URL: https://github.com/apache/logging-log4j2/issues/3257#issuecomment-2508300272
Hi @eldwrjwt, > I believe this is because the requiresLocation function in FailoverAppender is the default implementation in AbstractAppender, which relies on the layout inside the appender. However, for FailoverAppender, we do not have a layout, and thus fail to generate the location field in the log event object. Nice catch! :100: Can you submit a PR that fixes it? > Additionally, the Async logger uses a RingBufferLogEvent, which directly reads the location field, so there's no location to print. The **shouldn't** be a problem: - Log4j Core 2 uses the `o.a.l.l.spi.AbstractLogger` class from Log4j API, which populates the value of the location **early**: https://github.com/apache/logging-log4j2/blob/e1715dc9f3132c70f1a87a6a75058d02a0b69d63/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java#L2861 https://github.com/apache/logging-log4j2/blob/e1715dc9f3132c70f1a87a6a75058d02a0b69d63/log4j-api/src/main/java/org/apache/logging/log4j/spi/AbstractLogger.java#L2918-L2920 - Log4j Core 3 populates the location **just before** the asynchronous barrier to give filters a chance to discard it: https://github.com/apache/logging-log4j2/blob/7fd3a1303dec3ede639dd573851143c5ac0890e1/log4j-async-logger/src/main/java/org/apache/logging/log4j/async/logger/RingBufferLogEventTranslator.java#L61-L87 In both cases the `location` field is populated if `requiresLocation()` returns `true`. > This issue is also true for AsyncAppender. I agree, we have the same problem as in `Failover` here: the `AsyncAppender.requiresLocation()` implementation is incorrect. Could you submit a separate PR for this one? Note that `AsyncAppender` has an additional twist to make things interesting: it has an [`includeLocation` configuration attribute](https://logging.apache.org/log4j/2.x/manual/appenders/delegating.html#AsyncAppender-attr-includeLocation) that must be turned on to compute location. The implementation of `requiresLocation()` for the Async appender should probably be: `includeLocation ` is true and any of the downstream appenders has `requiresLocation() == true`. **Remark**: If location information is important to you, since last year we have a [Log4j Transform Maven plugin](https://logging.apache.org/log4j/transform/log4j-transform-maven-plugin.html), which precomputes the location of your log statements at build time. If the location is precomputed, it will be available regardless of any `includeLocation` setting: these settings prevent the **computation** of location information at runtime, they don't delete the information that is already there. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org