I have implemented log4j 2.12.4 as my logging framework. The application on which I am working consists of four WAR files. Three WAR files are directly related to my team while the other team is working on fourth WAR file. I have configured log4j2.xml in three of my WAR files while the fourth one have log4j.xml - means log4j 1.x.
My three WAR files logs are writing to a single log file (ABC.log) - I have defined and want in this way. And the logs of fourth WAR file are writing to another log file (XYZ.log). Now, the logging for ABC.log is working fine but on Console the logs pattern is very haphazard.
I am using Wildfly 9.0.2 as my application server. On console the logs are printing in a way like:
INFO : stdout - [23:17:05,641] [INFO] ClassA:177 - DateString: 2022-01-01
But in actual, I want to display it as:
[23:17:05,641] [INFO] ClassA:177 - DateString: 2022-01-01
Why the additional text in start of the log message is appearing? My POM file have following dependencies for log4j2:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.12.4</version>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>log4j2-jboss-logmanager</artifactId>
<version>1.0.0.Final</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>
Besides this wrong logging format on Console, one other issue is that the logs of my three WAR files are writing in the log file of fourth WAR also which is "XYZ.log" and in the wrong format too.
I don't want to get write my WAR files logs into "XYZ.log" and I have not configured that anywhere but it is writing.
I tried by adding jboss-deployment-structure.xml with following configurations but it didn't get fixed:
<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>
Please let me know what can be the issue of wrong logging format on Console and writing the logs in another log file which I haven't defined. Any help would be really appreciated!