I am upgrading log4j to v2.17.2 from v1.2.12 for an application that runs on jboss-esp-7.2 server. After updating the dependencies and classes, if I deploy on the server, I saw that the logs were not printing at all. This was resolved by adding log4j2.xml file as shown below -
<xml version=“1.0” encoding=“UTF-8”?>
<Configuration status=“INFO”>
<Appenders>
<Console name=“Console”>
<PatternLayout pattern=“%d{HH:mm:ss.SSS} %-5level [%logger{36}] (%t) %msg%n />
</Console>
</Appenders>
<Loggers>
<Root level=“info”>
<AppenderRef ref=“Console” />
</Root>
</Loggers>
</Configuration>
As the application is hosted on jboss-eap-7.2 server, we also have a configuration added for logging in standalone.xml as shown below -
<subsystem xmlns=“urn:jboss:domain:logging:6.0”>
<console-handler name=“CONSOLE”>
<level name=“INFO”/>
<formatter>
<pattern-formatter pattern=“%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n”/>
</formatter>
</console-handler>
<root-logger>
<level name=“INFO”/>
<handlers>
<handler name=“CONSOLE”/>
</handlers>
</root-logger>
</subsystem>
I am not sure why but I think the two configurations are conflicting and the logs from the application is printing under 2 levels, INFO stdout from server and under the message part, we see the actual log message as the pattern set in log4j2.xml in server.log file. This happens for any level set up at the application.
How it is printing- 19:22:38,188 INFO [stdout] (default task-1) 19:22:38.188 ERROR [com.application] (default task-1) actual error log message from application
How it should print - 19:22:38.188 ERROR [com.application] (default task-1) actual error log message from application
How can we resolve this?
I did figure out a way to print it properly by adding a file appender and moving all logs from the application to another file called application.log.
But I want to avoid this and try to keep all the logs in server.log file itself. Is there a way to do this?
jboss-deployment-structure.xml
in your deployment.