I'm deploying multiple WAR files in an apache tomcat server. each WAR file is containing their respective Log4j.properties file (Log4j located in WEB-INF/Log4j.properties).
If I'm deploying app1.WAR, having WEB-INF/classes/Log4j.properties to generate logs in CATALINA-HOME/logs/app1.log and another app2.WAR, having WEB-INF/classes/Log4j.properties to generate logs in CATALINA-HOME/logs/app2.log, but every logs from my both webapps are written into CATALINA-HOME/logs/app1.log.
how can I configure Log4j to create dedicated log file for each webapp loaded in apache?
I finally found a solution.
we just need to copy Log4j and commons lib jar files in the WEB-INF/lib folder of each WAR file to get an independent instance of Log4j per webapp. Then, Log4J will get the Log4j.properties file of the webapp to create its own Logging instance.
Hope it will help.
The solution by @tiamat didn't worked for me. I have to configure a listener to initialize logger context along with providing configuration location explicitly to the context
URL configLocation = Class.forName("com.example.MyAppListener").getResource("/log4j2.xml");
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.setConfigLocation(configLocation.toURI());
if(!context.isInitialized()) {
context.initialize();
}else {
context.reconfigure();
}
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.