logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Remko Popma <remko.po...@gmail.com>
Subject Re: flushing async loggers
Date Sun, 21 Jun 2015 23:30:52 GMT
Async loggers will call flush() when the queue is empty. If you are not seeing all expected
output in the file I suspect that async loggers are not actually enabled. 

You can verify with jstack or break your program in a debugger. There should be an "AsyncLogger..."
thread. 

How do you ensure your LogManager class is loaded before your app calls any other log4j code?

Remko

Sent from my iPhone

> On 2015/06/22, at 6:54, Serdyn du Toit <dutoitns@gmail.com> wrote:
> 
> Hi,
> 
> How do I flush async loggers?
> 
> I'm currently testing some code with multiple threads - when the test is
> finished almost none of the log statements have been printed.  This also
> makes me worried about my production code's logging when the server
> gracefully shuts down (will it just not log as it the case in my test, or
> will it actually flush...)
> 
> The only clue I've found on how to do this is the following stackoverflow
> thread:
> 
> http://stackoverflow.com/questions/3060240/how-do-you-flush-a-buffered-log4j-fileappender
> 
> But the solution just doesn't seem to work for me.
> 
> I don't think its relevant to the question, but here is my log4j.xml
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <configuration status="WARN">
>  <appenders>
> <Console name="CONSOLE" target="SYSTEM_OUT">
> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
> %msg%n" />
> </Console>
> <RollingRandomAccessFile name="FILE" fileName="logs/webapplog.log"
> 
> filePattern="logs/$${date:yyyy-MM}/webapplog-%d{yyyy-MM-dd}-%i.log.gz">
>      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} -
> %msg%n" />
>      <Policies>
>        <TimeBasedTriggeringPolicy />
>      </Policies>
>    </RollingRandomAccessFile>
>  </appenders>
>  <loggers>
> 
> ...snip...
> 
>    <root level="WARN">
>      <appender-ref ref="CONSOLE" />
>      <appender-ref ref="FILE" />
>    </root>
> </loggers>
> </configuration>
> 
> And then I have a LogManager class encapsulating all my logging code that
> enables async logging:
> 
> public class LogManager {
> 
> // Enable Log4j2 async logging
> static {
> System.setProperty("Log4jContextSelector",
> "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
> }
> 
>        ...etc...
> }
> 
> Any help appreciated!!!

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message