Log4j2 AsyncLogger with a sliding file application not displaying the file line number

Im using log4j2 with the following dependencies:

<!-- LOG4J2 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.0-rc1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.0-rc1</version> </dependency> <dependency> <groupId>com.lmax</groupId> <artifactId>disruptor</artifactId> <version>3.0.1</version> </dependency> 

The contents of Log4j2.xml:

 <?xml version="1.0" encoding="UTF-8"?> <Configuration status="OFF"> <Appenders> <Console name="CONSOLE" target="SYSTEM_OUT"> <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n" /> </Console> <!-- Generate rolling log for router with per hour interval policy --> <RollingFile name="ProcessorRollingFile" fileName="D:/ocsprocessor.log" filePattern="D:/ocsprocessor.log.%d{MM-dd-yyyy}-%i.log"> <PatternLayout> <pattern>%d{ISO8601} [%t] %p %c %L - %m%n</pattern> </PatternLayout> <Policies> <TimeBasedTriggeringPolicy interval="1" /> </Policies> <DefaultRolloverStrategy max="24" /> </RollingFile> <!-- Register Async appender --> <Async name="AsyncRollingFile"> <AppenderRef ref="ProcessorRollingFile" /> </Async> </Appenders> <Loggers> <AsyncLogger name="com.tritronik.logger.log4j2" level="error" additivity="false"> <AppenderRef ref="AsyncRollingFile" /> </AsyncLogger> </Loggers> </Configuration> 

It turned out that everything went fine, except that the log does not display the line number of the abandoned registrar (% L template in the template).

I googled and found out that for the asynchronous logger and the copied appender file, no one mentioned the use of% L, so how could I achieve it? Or does it not support% L?

Edit: I tried adding includeLocation = "true" , but still the same results

 2014-05-23 11:42:40,368 [threadPoolTaskExecutor-5] ERROR (AsyncLogger:) - THIS IS TEST MESSAGE FOR LOGGING TEST PURPOSE 

thanks

+6
source share
1 answer

First, uninstall the Async application and immediately point the appender-ref for AsyncLogger to the ProcessorLoggingFile. Secondly, you must add includeLocation = "true" in AsyncLogger.

Having an asynchronous application in addition to the asynchronous log does not help, in which case it may interfere with the function includeLocation.

+10
source

Source: https://habr.com/ru/post/969726/


All Articles