Log4j 2.0 - No aparecen registros en los archivos de registro - Probar múltiples registradores en la misma clase usando log4j2.xml

Below is the log4j2.xml file that I have created. I have configured async_file.log for Asynchronous Logging and regular_file.log for regular and synchronous logging. The problem is that the log files get created, but the size of the files is zero and with no logs. All logs are coming to server.log file (JBOSS) and not to the 2 files that I had got configured for (async_file.log and regular_file.log).

  • Please let me know why the logs are NOT going to the log files that I have configured. Please help me with this or give me some direction or hint.

I am calling the two different loggers in the same class file by name DCLASS as shown below:

private static final transient Logger LOG = Logger.getLogger(DCLASS.class);

private static final transient Logger ASYNC_LOG = Logger.getLogger("ASYNC");

I have included the following jars in the Class Path:
1. log4j-api-2.0-beta8.jar
2. log4j-core-2.0-beta8.jar
3. disruptor-3.0.0.beta1.jar

My log4j2.xml is as below:

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

<configuration status="INFO">
    <!-- Async Loggers will auto-flush in batches, so switch off immediateFlush. -->

    <FastFile name="AsyncFastFile" fileName="../standalone/log/async_file.log" 
              immediateFlush="false" append="true">
        <pattern>%d %p %class{1.} [%t] %location %m %ex%n</pattern>

    <FastFile name="FastFile" fileName="../standalone/log/regular_file.log" 
              immediateFlush="true" append="true">
        <pattern>%d %p %class{1.} [%t] %location %m %ex%n</pattern>

    <!-- pattern layout actually uses location, so we need to include it -->
    <asyncLogger name="ASYNC" level="trace" includeLocation="true">
      <appender-ref ref="AsyncFastFile"/>

    <root level="info" includeLocation="true">
      <appender-ref ref="FastFile"/>


preguntado el 09 de septiembre de 13 a las 22:09

1 Respuestas

The reason why the logs were not coming to the log files is because, I was using 'Logger' instead of 'LogManager'.

In the code, I had

private static final transient Logger ASYNC_LOG = Logger.getLogger("ASYNC");

El código debería haber sido

private static final transient Logger ASYNC_LOG = Logmanager.getLogger("ASYNC");

When it is 'logger', then the compiler is looking into 'Log4j API' and when it is 'LogManager' it is looking into 'Log4j2 API'. Since I have configured everything to use Log4j2, by changing logger to LogManager, the logs started coming to the log files as expected.

Respondido el 09 de Septiembre de 13 a las 23:09

Glad you solved it! Two remarks: you may want to use a more recent version of the disruptor (latest is 3.2) and in the upcoming log4j2 beta-9, the FastFile appender has been renamed to RandomAccessFile appender, and you'll need to update your config when you switch. Just a heads-up. - Remko papá

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.