On 17/03/2020 06:05, Brian Burch wrote:
> I have a very frozen and stable tomcat 7.0.68 system with a lot of apps.
> It was build from source and uses the extras tomcat-juli.jar with
> log4j-1.2.17.jar.
> Both tomcat and my webapps log successfully via log4j (except, of
> course, the access log valve).
> The time has come to bring the whole system up to date, but I don't want
> to jump too far in a single leap, so I am trying to port the production
> environment to a new server image. (The old system is ubuntu 16.04.6 LTS
> 32-bit. The new system is 18.04.3 LTS 64-bit).


> I would be very grateful for any advice to make my tomcat8 use log4j2. I
> hope this advice will permit me to recommend some improvements to the
> relevant pages of the tomcat wiki...

I haven't test this extensively so there may be some edge case that need

Some background for those who may be less familiar with the topic.

JULI, as provided by Tomcat, is a packaged renamed version of Apache
Commons Logging hard-coded to output to java.util.logging.

The old log4j extras package (still present in Tomcat 7) was a packaged
renamed version of Apache Commons Logging hard-coded to output to log4j v1.

Essentially, there were two logging implementations and you picked the
one you wanted.

With log4j v1 reaching end-of-life, Tomcat 8.5.x onwards has the option
of outputting to log4j v2 but the way it is configured is very different.

log4j v2 provides an adaptor that lets it "intercept" log messages sent
to java.util.logging. The idea is that this adapter is used with Tomcat
8.5.x onwards.

The configuration steps are (using v2.13.1):

0. Leave the Tomcat logging configuration as is.

1. Add the required log4j JARs. They are:
   - log4j-jul-2.13.1.jar
   - log4j-api-2.13.1.jar
   - log4j-core-2.13.1.jar

Where you put them doesn't really matter. For consistency with Tomcat
I'd place them in the bin directory.

2. Add the required configuration file. For consistency with Tomcat I'd
call it log4j2.xml and place it in the conf directory. The file I used was:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36}
- %msg%n"/>
    <Root level="info">
      <AppenderRef ref="Console"/>

This is essentially the default config but with the logging level
changed to info so you actually see something.

3. You then need to configure:
   - the java.util.logging logging manager so log4j v2 intercepts the
     log messages
   - the configuration file so the right messages are logged
   - the classpath so the log4j v2 JARs are found.

You can do all of this in setenv.[sh|bat]. The file I used was:


Excuse the poor formatting with line wrapping and adjust appropriately
if you are on Windows.

I used CATALINA_BASE above but it works equally well with CATALINA_HOME.
If you have split HOME and BASE you can configure this on either.

All of this was with Tomcat 10 but it should be the same with 9.0.x and

A patch or PR to add the above (once you have confirmed it is complete)
to https://github.com/apache/tomcat/blob/master/webapps/docs/logging.xml
would be very helpful.

> Thanks in anticipation,
> Brian
> (back on the list after nearly 4 years away!)

Welcome back.

To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to