I have looked up similar questions but none of the answers really fixed the problem. I have a Spring Boot application configured to use slf4j+log4j2 (with an internal log4j2.xml config in src/main/resources
). I deploy this war on JBoss EAP (6.4 & 7) and can see log traces from JBoss startup. The problem is that log4j2 appenders just don't print anything, neither on console nor on the file:
In the console only the jboss logging logs show up (every log.info() in my appplication traces with jboss logging format).
A c:\logs\out.log
file is created but nothing is written on it.
These are the things I have done:
I have debugged and checked that Spring Boot's Log4J2LoggingSystem
is correctecty initialized with the classpath:log4j2.xml
file.
My application is using SLF4J and while debugging I have seen that the underlying logging implementation is JBoss' logging instead of Log4j2
The log4j2 logging works correctly on Tomcat.
In standalone.xml I have removed <extension module="org.jboss.as.logging"/>
and the <subsystem xmlns="urn:jboss:domain:logging:3.0">
block. After doing this, only a few jboss traces are printed on the console (but nothing from the application log.info()), but the log4j2 file appender prints correctly.
How can in configure JBoss to support the application's log4j2.xml printing on the console and a file?
log4j2.xml excerpt:
<Configuration status="WARN">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout ...
<RollingFile name="file"
filePattern="'.'%d{yyyy-MM-dd}"
fileName="c:\logs\out.log">
<PatternLayout
pattern="%d{yyyy-MM-dd'T'HH:mm:ss.SSS} - %c{1.} %5p - %m%n" />
<Policies>
<TimeBasedTriggeringPolicy />
</Policies>
</RollingFile>
<Logger name="org.springframework" level="info" additivity="false">
<AppenderRef ref="file" />
<AppenderRef ref="console" />
</Logger>
</Configuration>
UPDATE
The problem has to do with the way JBoss manages SLF4J:
org.slf4j.Logger slf4jLogger = org.slf4j.LoggerFactory.getLogger(PresupuestoController.class);
org.apache.logging.log4j.Logger log4j2Logger = LogManager.getLogger(PresupuestoController.class);
If I run slf4jLogger.info("SLF4J!!!");
. It prints with the underlying JBoss Logger:
11:19:03,122 INFO [com.my.web.SomeController] (default task-2) SLF4J!!!
but when I execute log4j2Logger.info("LOG4J2!!!");
it prints on the console following my log4j2.xml configuration:
11:19:03,668 INFO [stdout] (default task-2) 2016-05-19T11:19:03.663 c.m.w.SomeController INFO - LOG4J2!!!
As as requirement I have to use SFL4J in the code so I need a way to force it to use Log4j2 instead of JBoss.
After struggling with this, here is what finally worked it out: adding ajboss-deployment-structure.xml
file to my WEB-INF folder with this content:
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name='org.slf4j' />
<module name='org.slf4j.impl' />
</exclusions>
</deployment>
</jboss-deployment-structure>
Now JBoss logging keeps working but also allows me to use SFL4J + Log4j2 in my app code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With