Hi All:

I have a web application that uses log4j (v2.20) which runs inside Tomcat 9.x on Java 8.

Currently, the WEB-INF/log4j2.xml configuration file in the application sends its output to a rolling file appender targeting a separate file on the file system, but what I'd like to do is make all log4j output go to the regular per-application log under ${catalina_base}/logs which is managed by the stock Tomcat JULI implementation.

We now have the log4j-to-jul module which can adapt log4j 2 output back to java.util.logging. Similar to my understanding of the purpose for log4j-to-slf4j, it seems that log4j-to-jul is meant to be used as an implementation by itself for log4j-api and without log4j-core.

The application currently uses log4j-web to get the all the essential setup for initializing log4j 2 under an application container. The log4j-web library appears to have a hard dependency on log4j-core.

After adding log4j-to-jul to the application classpath, I can see that it is recognized:
Multiple logging implementations found:
Factory: org.apache.logging.log4j.core.impl.Log4jContextFactory, Weighting: 10 Factory: org.apache.logging.log4j.tojul.JULLoggerContextFactory, Weighting: 20

But then the following error is reported:
ERROR StatusLogger LogManager returned an instance of org.apache.logging.log4j.tojul.JULLoggerContextFactory which does not implement org.apache.logging.log4j.core.impl.Log4jContextFactory. Unable to initialize Log4j.

In org.apache.logging.core.config.Configurator, line 47 there is a conditional that checks the return type of the logging implementation is-a Log4jContextFactory. The problem is then that JULLoggerContextFactory implements only LoggerContextFactory.

I'd like to keep my tomcat container as stock as possible. Particularly, continuing to use the built-in JULI per-application logging and *not* switching the entire container to use log4j as its logging implementation.

Can anyone suggest how I can use log4j-to-jul successfully for my use case?

Thanks,
Jason


---------------------------------------------------------------------
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