Hi All:

Thank you all for your help and the good information about log4j-web and log4-core.

I already had my per-application logging configured in WEB-INF/logging.properties and all output is going to the same log file now that I've switched to log4j-to-jul.

Cheers,
Jason

On 6/2/2023 2:13 PM, Jason Guild wrote:
CAUTION: This email originated from outside the State of Alaska mail system. Do not click links or open attachments unless you recognize the sender and know the content is safe.

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


--
Jason Guild
Systems Programmer
Alaska Department of Transportation & Public Facilities
Statewide Administrative Services
820 E. 15th Ave.
Anchorage, Alaska 99501

Reply via email to