> On May 12, 2022, at 4:16 AM, Dave Piper (HE/HIM)
> <davepi...@microsoft.com.INVALID> wrote:
>
> 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)
> - ...
When using the ClassLoaderContextSelector you do not need log4j jars in each
web app. However, You should only have the one set in the tomcat/lib directory.
>
>
> 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.
When the ClassLoaderContextSelector is used (the default) Log4j will use the
caller’s ClassLoader to determine the LoggerContext to use when obtaining a
Logger. Each LoggerContext should tie it to the Configuration for all the
Loggers for classes in that ClassLoader. Note that Log4j is, by default, going
to look for the log4j2.xml on the classpath. So in Tomcat it should find the
appropriate log4j2.xml since tomcat won’t look at web app ClassLoaders and
tomcat normally uses child first loading so should find the web apps log4j2.xml
in WEB-INF/classes.
I would suggest removing the log4j-xxx jars in the web apps and see what
results you get.
Ralph
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org