dedeibel opened a new issue, #2781:
URL: https://github.com/apache/logging-log4j2/issues/2781

   ## Description
   
   When using _all async loggers_ and `<PatternLayout pattern="(%F) - %m%n" />` 
the file name (location information) is missing although 
`includeLocation="true"` is configured.
   
   ### Observed
   
   `() - Hello, World!`
   
   ### Expected
   
   `(Log4j2Example.java) - Hello, World!`
   
   ## Configuration
   
   **Version:** 2.23.1, 3.0.0-beta2, 3.0.0-SNAPSHOT
   
   **Operating system:** Linux, debian 12.5
   
   **JDK:** OpenJDK Runtime Environment 21.0.2+13-58
   
   Using _all async loggers_.
   
   
`-Dlog4j2.contextSelector=org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector`
   
   - https://logging.apache.org/log4j/2.3.x/manual/async.html
   
   For newer versions the class name is 
`org.apache.logging.log4j.async.logger.BasicAsyncLoggerContextSelector` but not 
yet reflected in https://logging.apache.org/log4j/3.x/manual/async.html The 
property name also varies in versions > 2.23.1 so please adapt to your 
situation.
   
   ## Logs
   
   
[log4j2example-log-before-pub.txt](https://github.com/user-attachments/files/16428453/log4j2example-log-before-pub.txt)
   
   ## Reproduction
   
   ### log4j.xml
   
   ```xml
   <?xml version="1.0" encoding="UTF-8"?>
   <Configuration status="TRACE">
       <Appenders>
           <Console name="Console" target="SYSTEM_OUT">
               <PatternLayout pattern="(%F) - %m%n" />
           </Console>
       </Appenders>
       <Loggers>
           <Root level="DEBUG" includeLocation="true">
               <AppenderRef ref="Console" />
           </Root>
       </Loggers>
   </Configuration>
   ```
   
   ### Log4j2Example.java
   
   ```java
   import org.apache.logging.log4j.LogManager;
   import org.apache.logging.log4j.Logger;
   
   public class Log4j2Example {
   
       static {
           /* Enable all async loggers variant 1: Note: does not seem to have 
an effect in versions after 2.23.1 */
           System.setProperty(
                   "log4j2.contextSelector",
                   
"org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector");
   
           /* Enable all async loggers variant 2: Apparently a different 
property name has to be set in 3.0.0-beta2
            * Loaded from 
org.apache.logging.log4j.util.SystemPropertiesPropertySource.getProperty(String,
 String) Line #97 */
           System.setProperty(
                   "LoggerContext.selector",
                   
"org.apache.logging.log4j.async.logger.BasicAsyncLoggerContextSelector");
   
           /* Enable all async loggers variant 3: For main branch 
3.0.0-SNAPSHOT (tested e0993ae) I could not figure out
            * the working appropriate property name. Development seems to be 
hot in this area atm. Please set the
            * environment variable:
            * 
            * 
LOG4J_LOGGER_CONTEXT_SELECTOR=org.apache.logging.log4j.async.logger.BasicAsyncLoggerContextSelector
            */
   
           /* See more about what is going on - look out for 
"AsyncLoggerDisruptor" in the logs to see if configuration was
            * successful. */
           
System.setProperty("org.apache.logging.log4j.simplelog.StatusLogger.level", 
"TRACE");
       }
   
       private static final Logger logger = LogManager.getLogger("HelloWorld");
   
       public static void main(String[] args) {
           logger.info("Hello, World!");
       }
   
   }
   ```
   
   ### Full example
   
   ## Analysis / Solution
   
   # v2.23.1
   
   For v2.23.1 I could track the issue down to the  fact that 
`FileLocationPatternConverter` does not implement `LocationAware` and define 
`boolean requiresLocation() { return true; }`. In contrast to 
`ClassNamePatternConverter`.
   
   From my understanding the async logger tries to determine rather dynamically 
if the location is required which fails here. I suspect if someone had `%C and 
%F` in a pattern the error would not show.
   
   # 3.0.0-SNAPSHOT
   
   There is no interface `LocationAware` anymore but the converters have their 
own `requiresLocation` method with the same signature that can be implemented.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to