All,

I have a web application which contains a log4j2.xml file in the WEB-INF directory. If I provide the full path using -Dlog4j.configurationFile=[path]/log4j2.xml, then log4j configures as I expect. Without this parameter, log4j does not find the configuration file.

I have the log2j libraries api, core, web, and 1.2 all installed into the web application. The web module configuration reference[1] says that files called log4j2* will be searched-for in the WEB-INF directory, but it looks like my file is not found.

I enabled debug logging, and this is what log4j says during autoconfiguration:

DEBUG StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory@3fed9a4 TRACE StatusLogger Trying to find [log4j2-test35dba0ad.properties] using context class loader ParallelWebappClassLoader

There follow a series of attempts to find files called log4j2-test35dba0ad.(properties|yml|yaml) and log4j2-test.(properties|yml|yaml) using the ParallelWebappClassLoader (which is the ClassLoader provided by Apache Tomcat). The ClassLoader will only look for resources in WEB-INF/lib/*.jar and WEB-INF/classes but not WEB-INF itself. Looking in WEB-INF/ requires a different kind of look-up.

This is also present in the log:

TRACE StatusLogger Trying to find [log4j2-test35dba0ad.properties] using ClassLoader.getSystemResource().

This is falling-back to using the system classloader, which of course won't find this file.

I think the documentation may be wrong; log4j doesn't appear to be looking in WEB-INF/ for files. Instead, it's using the ClassLoader which won't look there.

Moving my log4j2.xml file from WEB-INF/ to WEB-INF/classes allows log4j to find the file and use it for configuration as expected.

-chris

[1] https://logging.apache.org/log4j/2.x/manual/webapp.html

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-user-h...@logging.apache.org

Reply via email to