Bug 63293 - Tomcat 9.0 logging not working with log4j1.2 after upgraded from Tomcat 8.0
Summary: Tomcat 9.0 logging not working with log4j1.2 after upgraded from Tomcat 8.0
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 9.0.13
Hardware: PC All
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-27 18:31 UTC by twsatwork
Modified: 2019-03-27 22:42 UTC (History)
1 user (show)



Attachments
This archive contains log4j configuration and sample Tomcat server.log files. (1.48 KB, application/x-zip-compressed)
2019-03-27 18:31 UTC, twsatwork
Details

Note You need to log in before you can comment on or make changes to this bug.
Description twsatwork 2019-03-27 18:31:09 UTC
Created attachment 36500 [details]
This archive contains log4j configuration and sample Tomcat server.log files.

[Title]
Tomcat 9.0 logging not working with log4j1.2 after upgraded from Tomcat 8.0



[Frequency of Occurrence]
Always



[System/Software Info]
OS: Red Hat Enterprise Linux Server release 7.6 (Maipo)
Tomcat: 8.0.52 and 9.0.13
Tomcat Native: 1.2.17
Tomcat APR: 1.6.3
OpenSSL: 1.0.2o
OpenJDK (JRE): 1.8.0-171-b11



[Details]
1. log4j 1.2.15 is used as the logging library with Tomcat.

2. A custom log4j configuration is used (see the attached "log4j.properties").
(1) log4j rootLogger is set to INFO, FILE
(2) The FILE appender is set to ${catalina.base}/logs/server.log

3. The same environment is used to run Tomcat.  The only difference before and after the Tomcat upgrade is Tomcat itself.
(Note there exists change in FormAuthenticator and the use of LegacyCookieProcessor as the CookieProcessor for backward compatibility.)

4. When running with Tomcat 8.0.52, some INFO logs from Tomcat (org.apache.catalina.*) appear in ${catalina.base}/logs/server.log"

5. When running with Tomcat 9.0.13, the file ${catalina.base}/logs/server.log is basically empty.

6. Refer to the attached sample server.log files from 8.0.52 and 9.0.13.

7. I checked the source code "org.apache.catalina.core.StandardService.java" in Tomcat 9.0.13. One logging statement in the code looks the same to me.  However, I see this log with 8.0.52 but not 9.0.13.

8. This issue is observed in 9.0.13 (and higher).

// --- code Snippet [S] ---
... ...
    protected void startInternal() throws LifecycleException {

        if(log.isInfoEnabled())
            log.info(sm.getString("standardService.start.name", this.name));  // <--- This log appears with 8.0.52
        setState(LifecycleState.STARTING);

        // Start our defined Container first
        if (engine != null) {
            synchronized (engine) {
                engine.start();
            }
        }
... ...
// --- code Snippet [E] ---

8. I looked up in the release notes and migration info but seem not seeing Tomcat 9 would not work with log4j1.2.

9. The issue is also observed in Windows platform.



[Prerequisites]
1. Tomcat 8.0.52 and 9.0.13
2. OpenSSL library. See the References section.
3. APR library for Linux. See the References section.
4. Tomcat Native library for Linux (this needs to be built from the source code.  Tomcat does not include this for Linux.) See the References section.
5. Tomcat needs to be set up using APR/OpenSSL with proper certificate(s).



[Setup Steps]
1. Ensure the following files exist under ${catalina.base}\lib
(1) log4j.jar (v. 1.2.15)
(2) log4j.properties



[Procedure To Reproduce]
1. Start Tomcat 8.0.52 and check the file ${catalina.base}/logs/server.log
2. Start Tomcat 9.0.13 and check the file ${catalina.base}/logs/server.log



[References]
1. Tomcat
(1) Main: https://tomcat.apache.org/index.html
(2) 8.0.52 download: https://archive.apache.org/dist/tomcat/tomcat-8/v8.0.52/
(3) 9.0.13 download: https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.13/

2. log4j1.2
(1) Main: https://logging.apache.org/log4j/1.2/index.html
(2) 1.2.15: Download: http://archive.apache.org/dist/logging/log4j/1.2.15/

3. Tomcat APR:
(1) Main: http://apr.apache.org/
(2) 1.6.3 download: http://archive.apache.org/dist/apr/

4. Tomcat Native
(1) Main: https://tomcat.apache.org/native-doc/
(2) 1.2.17 download: https://archive.apache.org/dist/tomcat/tomcat-connectors/native/1.2.17/

5. OpenSSL
(1) Main: https://www.openssl.org/
(2) 1.0.2o: https://www.openssl.org/source/old/1.0.2/
Comment 1 Mark Thomas 2019-03-27 19:23:56 UTC
Bugzilla is not a support forum. Please use the users mailing list.
Comment 2 twsatwork 2019-03-27 20:50:49 UTC
Mark,

Thanks for the quick review. However, I didn't ask how to use log4j1.2 with Tomcat.  I have it working properly with Tomcat 6.0/7.0/8.0.  Now, I tried to upgrade to Tomcat 9.0 and the same logging setup no longer works. There is no change in any of the code or configuration on my part, the only difference is Tomcat image- from 8.0 to 9.0.  Therefore, would it be natural to look into what may change in Tomcat 9.0 in this case?

I understand that things may change in a major upgrade between releases.  But I'd expect the important changes would be noted in the release notes and/or migration guide. I checked Tomcat online documentation and didn't find any reference that log4j1.2 can't be used with Tomcat 9.0.  I also looked up the bug list and didn't find anything before submitting this report.

I attempted to dig it further in Tomcat source code but couldn't get too far.
Comment 3 Konstantin Kolinko 2019-03-27 20:57:59 UTC
Apache Log4j 1.x has officially reached End of Life.

Tomcat 9.0 has no support for it (since Tomcat 9.0.0.M7, see changelog).

The rest is a topic for the mailing list (don't forget to search the archives).
Comment 4 twsatwork 2019-03-27 22:42:58 UTC
(In reply to Konstantin Kolinko from comment #3)
> Apache Log4j 1.x has officially reached End of Life.
> 
> Tomcat 9.0 has no support for it (since Tomcat 9.0.0.M7, see changelog).
> 
> The rest is a topic for the mailing list (don't forget to search the
> archives).

Konstantin,

Thank you very much for the prompt clarification and kind direction to the relevant information in Tomcat 9.0 changelog.

As for the my own reference, the detailed info may be found at the link:

https://tomcat.apache.org/tomcat-9.0-doc/changelog.html

See the sections Catalina and Extras under Tomcat 9.0.0.M7.

Thanks again.