Search code examples
javaloggingconfigurationlog4j2disruptor-pattern

log4j2 configuration with disruptor


I am trying to use log4j2 with disruptor in a java application. I have the following jar files in my classpath:

  1. log4j-api-2.0-rc2.jar
  2. log4j-core-2.0-rc2.jar
  3. disruptor-3.2.0.jar

In my Java class, I a doing the following to test:

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

public class LoggerTest {   
     private static final Logger Logger = LogManager.getLogger(LoggerTest.class.getName());

    public static void main(String[] args) {
        Logger.info("testing log4j2 with disruptor");
}

My log4j2.xml file is as follows:

<?xml version="1.0" encoding="UTF-8"?>

<!-- Don't forget to set system property 
-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
     to make all loggers asynchronous. -->

<configuration status="INFO">
  <appenders>
    <!-- Async Loggers will auto-flush in batches, so switch off immediateFlush. -->
    <FastFile name="RandomAccessFile" fileName="logs/test.log" immediateFlush="false" append="false"> 
      <PatternLayout>
        <pattern>%d %p %c{1.} [%t] %m %ex%n</pattern>
      </PatternLayout>
    </FastFile>
  </appenders>
  <loggers>
    <root level="info" includeLocation="true">
      <appender-ref ref="RandomAccessFile"/>
    </root>
  </loggers>
</configuration>

When I run the application, I get the following error (with no log output):

2014-07-10 14:45:32,930 ERROR Error processing element FastFile: CLASS_NOT_FOUND
2014-07-10 14:45:32,973 ERROR Unable to locate appender RandomAccessFile for logger 

Solution

  • In beta9, the <FastFile> appender was renamed to <RandomAccessFile>. If you rename this element in your configuration it should work.