Hi,

We've been using log4j for over a decade to produce logs for various webapps 
within a single tomcat instance. Some of our loggers and file appenders are 
defined within the tomcat/lib folder itself so that they're picked up by the 
common classloader and can be shared by multiple webapps. The intention of this 
was to remove the risk of separate webapp processes writing to the same file 
simultaneously and causing write issues. We also have per-webapp log4j config.

Our file system is laid out as follows:

- tomcat
- tomcat/lib/log4j2.xml   (defines shared appenders and loggers)
- tomcat/lib/log4j-core.jar (and other log4j jars)
- ...
- tomcat/webapps/mywebapp1/WEB-INF/classes/log4j2.xml  (defines appenders and 
loggers for webapp 1)
- tomcat/webapps/mywebapp1/WEB-INF/lib/log4j-core.jar  (and other log4j jars)
- ...
- tomcat/webapps/mywebapp2/WEB-INF/classes/log4j2.xml  (defines appenders and 
loggers for webapp 2)
- tomcat/webapps/mywebapp2/WEB-INF/lib/log4j-core.jar   (and other log4j jars)
- ...


This was working as designed when we were using tomcat 8 and log4j v1, but 
since moving to tomcat 9 and log4j v2 we're no longer able to load both config 
files. When log4j logging is set to debug in tomcat, catalina.out shows that 
tomcat discovers and processes the webapp-specific log4j2.xml files but not the 
one under log4j2.xml.  We can configure tomcat / log4j so that each webapp 
loads multiple config files, but we think it's only loading those on a 
per-webapp basis, I think it's not loading one shared XML file so we don't get 
shared appenders. Having log4j v2 jars in multiple locations is also causing 
various errors.

Has anyone tried something similar to this? Is it still possible to load log4j 
config from both shared classloader and webapp levels, or do we need to find an 
alternative solution?

Any help much appreciated!

Cheers,

Dave

Reply via email to