logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Serdyn du Toit <dutoi...@gmail.com>
Subject flushing async loggers
Date Sun, 21 Jun 2015 21:54:02 GMT
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!!!

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message