0

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?

1
  • If you want to use log4j2 I'd suggest excluding the logging subsystem in a jboss-deployment-structure.xml in your deployment. Commented May 17 at 14:34

1 Answer 1

0

To have JBoss EAP use Log4j2 for logging, you need to configure JBoss EAP's logging subsystem to delegate logging to Log4j2. This can be done by using the log4j-jboss-logmanager module. Update the logging subsystem configuration as follows:

<subsystem xmlns="urn:jboss:domain:logging:6.0">
<custom-handler name="LOG4J2" class="org.jboss.logmanager.log4j.Log4j2Handler" module="org.jboss.logmanager.log4j2">
    <level name="ALL"/>
    <properties>
        <property name="log4j.configurationFile" value="${jboss.server.config.dir}/log4j2.xml"/>
    </properties>
</custom-handler>
<root-logger>
    <level name="INFO"/>
    <handlers>
        <handler name="LOG4J2"/>
    </handlers>
</root-logger>

This configuration instructs JBoss to use Log4j2 for logging. Ensure the log4j2.xml file is placed in the ${jboss.server.config.dir} directory. Then remove redundant logging confs that you mentioned.

5
  • I am getting an error that’s says it is not able to find the Log4j2Handler class. Which jar are you referring to in this case? Commented May 14 at 10:19
  • <dependency> <groupId>org.jboss.logmanager</groupId> <artifactId>log4j2-jboss-logmanager</artifactId> <version>1.0.9.Final</version> <!-- Use the appropriate version --> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.17.2</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.17.2</version> </dependency> Commented May 14 at 11:26
  • This will not work with JBoss EAP 7.2. JBoss EAP 7.2 does not ship with log4j2. You could include the org.jboss.logmanager:log4j2-jboss-logmanager in your deployment and use the logging subsystem for the configuration though. Commented May 17 at 14:32
  • @JamesR.Perkins Is there any other way to do this? As you said, the above method did not work. Commented May 27 at 10:08
  • Did you include the org.jboss.logmanager:log4j2-jboss-logmanager in your deployment along with the org.apache.logging.log4j:log4japi? Commented May 30 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.