Issue
I am using Spring Boot and Apache Camel in my application and deploying in JBoss EAP 7.3.0 as war files. Previously the startup logs and logs from the application were getting logged to the log file when I was using log4j 1.x and the below log4j.properties:
log4j.rootLogger = INFO, out, FILE
log4j.appender.out=org.apache.log4j.ConsoleAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.File=fileName.log
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd
log4j.appender.FILE.MaxFileSize=200MB
log4j.appender.FILE.MaxBackupIndex=20
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p %c{1}:%L - %m%n
Now I have shifted to log4j 2.17.1 and using the below lg4j2.properties:
rootLogger.level = INFO
property.filename = fileName.log
appenders = FILE, console
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d %5p [%t] (%F:%L) - %m%n
appender.FILE.type = RollingFile
appender.FILE.name = File
appender.FILE.fileName = ${filename}
appender.FILE.filePattern = ${filename}.%d{yyyy-MM-dd}
appender.FILE.layout.type = PatternLayout
appender.FILE.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
appender.FILE.policies.type = Policies
appender.FILE.policies.time.type = TimeBasedTriggeringPolicy
appender.FILE.policies.time.interval = 1
rootLogger.appenderRefs = FILE, console
rootLogger.appenderRef.console.ref = STDOUT
rootLogger.appenderRef.FILE.ref = File
But now only the below logs are coming during application startup and no logs are gettig logged from the application:
2022-08-13 00:52:12 ContextLoader [INFO] Root WebApplicationContext: initialization started 2022-08-13 00:52:31 ContextLoader [INFO] Root WebApplicationContext initialized in 19250 ms
Can anyone please suggest what am I doing wrong?
To add, I can see the logs from Spring Boot ApplicationContext during startup, but not the logs which are logged by the application. This is kind of strange.
Solution
Also I don't know how exactly you have it configured and packaged, but you may need to exclude the logging subsystem via jboss-deployment-structure.xml (located in war/WEB-INF or ear/META-INF):
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<deployment>
<exclude-subsystems>
<!-- disable the logging subsystem because the application manages its own logging independently -->
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
In the case of ear you'll also need to handle exclusions for any included modules via the sub-deployment elements, or try to use ear-exclusions-cascaded-to-subdeployments (available since jboss-deployment-structure:1.3):
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.3">
<ear-exclusions-cascaded-to-subdeployments>true</ear-exclusions-cascaded-to-subdeployments>
<deployment>
<exclude-subsystems>
<!-- disable the logging subsystem because the application manages its own logging independently -->
<subsystem name="logging" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
Answered By - Petr H
Answer Checked By - Cary Denson (JavaFixing Admin)