I have upgraded my log4j from 1.2.7 to log4j 2.12.4. I have three WAR files for which I want all the logs (from all WAR files) in a same log file "ABC.log". I have created log4j2.xml for each WAR file and have placed it under classpath "WEB-INF/classes/log4j2" but the logging is not working as required. Even the file (ABC.log) is not creating at all in the specified path (c:/logs/ABC.log).
I am using Wildfly 9.0.2 as my application server. Here are my POM file dependencies for log4j2:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.12.4</version>
</dependency>
And here are my log4j2.xml configurations:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="LogToConsole" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss,SSS}] [%p] %c{1}:%L - %m%n"/>
</Console>
<RollingFile name="LogToRollingFile" fileName="c:/logs/ABC.log"
filePattern="c:/logs/ABC-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<Pattern>[%d{HH:mm:ss,SSS}] [%p] %c{1}:%L - %m%n</Pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="500 KB"/>
</Policies>
<DefaultRolloverStrategy max="20"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.example" level="info" additivity="false">
<AppenderRef ref="LogToConsole"/>
<AppenderRef ref="LogToRollingFile"/>
</Logger>
</Logger>
<Logger name="org.jboss" level="error" additivity="false">
<AppenderRef ref="LogToConsole"/>
</Logger>
</Logger>
<Root level="error">
<AppenderRef ref="LogToConsole"/>
</Root>
</Loggers>
</Configuration>
One more thing is that logging is working fine on CONSOLE but for file, it is not working at all.
Please guide me how to make log4j2 configurable with Wildfly so that I can get all three WAR files logs into a single log file. Any help would be really appreciated!
I tried by adding jboss-deployment-structure.xml with following configurations but it didn't worked either:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.commons.logging" />
<module name="org.apache.log4j" />
<module name="org.jboss.logging" />
<module name="org.jboss.logging.jul-to-slf4j-stub" />
<module name="org.jboss.logmanager" />
<module name="org.jboss.logmanager.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
</exclusions>
</deployment>
</jboss-deployment-structure>