I'm working on a JEE REST API and am converting to log4j2. Some of my logging is working, but not others.
I created an appender, monitorAppender. Here's its configuration:
<RollingFile name="monitorAppender" append="true" fileName="${baseDir}/ZDA_monitor.log" filePattern="${baseDir}/ZDA_monitor.log.%i">
<PatternLayout pattern="%d{yyMMddHHmmssSSS}|%m%x%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="10 MB"/>
</Policies>
<DefaultRolloverStrategy max="5"/>
</RollingFile>
And logger configuration:
<Logger name="ZDAMonitor" level="info" additivity="false">
<AppenderRef ref="monitorAppender"/>
</Logger>
In my code when I try to use the logger:
LogManager.getLogger("ZDAMonitor").fatal("Test123");
I see this in the console, instead of the file:
SystemOut O 14:56:50.922 [WebContainer: 1] FATAL ZDAMonitor - Test123
I can't tell what's wrong with the config. I turned on debug logging for log4j and see in the startup logs it's being correctly loaded:
SystemOut O 2023-01-25 14:56:43,490 WebContainer: 1 DEBUG Registering MBean org.apache.logging.log4j2:type=5745d2fa,component=Loggers,name=ZDAMonitor
I can't post the source as this is a company project, but I'm using gradle, log4j-core and api 2.19.0, and WebSphere 8.5.5.22 with Java 1.8.
I've checked and double checked the configuration and code, and cannot find anything wrong with it.
WebSphere has a very peculiar thread context classloader.
The log4j-web
module configures a logger context associated to the context classloader. However the context classloader in WebSphere is not the classloader that loaded the classes in your application, so your application's loggers use a different logger context (and a different config). See LOG4J2-3577 for details.
A simple solution would be to use a BasicContextSelector
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.