log4j2.xml config file is not being loaded

Viewed 931

I have upgraded my log4j from 1.2.17 to 2.16.0. Therefore I had to rewrite my log4j.xml as well as to rename it to log4j2.xml. I have made the necessary changes. However it seems that my new config is not loaded. I have tried to configure log4j through both web.xml :

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>classpath:log4j2.xml</param-value>
</context-param>

and -Dlog4j2.configurationFile. Both approaches failed and I am not getting any logs in mylog.log file. However when running the application locally the Console display the logs.

This is my log4j2.xml :

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

<Configuration status="trace">
    <Appenders>
      <Console name="STDOUT" target="SYSTEM_OUT">
        <PatternLayout pattern="%-5p %c{1} - %m%n"/>
      </Console>
      <RollingFile name="DAILY_LOG" fileName="${catalina.base}/logs/mylog.log"
                   filePattern="${catalina.base}/logs/mylog.log.%d{yyyy-MM-dd}">
        <PatternLayout pattern="%d %-5p [%c] [%X{sid}:%X{uid}] %m%n "/>
        <Policies>
          <TimeBasedTriggeringPolicy interval="1"/>
        </Policies>
      </RollingFile>
    </Appenders>

    <Loggers>
       <!-- Limit the org.springframework category to INFO as its DEBUG is verbose -->
       <Logger name="org.springframework" level="INFO"/>
       <!-- Limit the org.hibernate category to INFO as its DEBUG is verbose -->
       <Logger name="org.hibernate" level="INFO"/>
       <!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
       <Logger name="org.apache" level="INFO"/>
       <Logger name="org.myproject" level="INFO"/>
       <!-- Root Logger -->
       <Root level="INFO">
         <AppenderRef ref="STDOUT"/>
         <AppenderRef ref="DAILY_LOG"/>
       </Root>
    </Loggers>
</Configuration>

I have tried to debug log4j configuration by using : -Dorg.apache.logging.log4j.simplelog.StatusLogger.level=trace. I have noticed that the LoggerContext instance is well created and all listed loggers are as well built.

I wonder if my config is wrongly written. Can someone please confirm or deny this to me.

1 Answers
Related