Replaced Tomcat 8.5 log output with Log4j2.8 or later

Changes in the log output of Tomcat 8.5 series

Unlike the Tomcat 8.0 series, the 8.5 series log output has some changes.

This time I will replace it with Log4j2, but with Log4j2.4 and earlier methods, it will be ** ignored ** at all.

How to output from Log4J 2.8.2

The procedure is as follows:

  1. Copy the log4j2 jar to tomcat
  2. Place the log4j2 configuration file
  3. Add the path to the log4j2 config file to the environment variable

1. Copy the log4j2 jar to tomcat

Download the set of log4j2 from https://logging.apache.org/log4j/2.x/download.html → unzip it. Next, put the jar file that can be eaten as the standard log adapter of Tomcat and the jar of Log4J2 main body to lib of the Tomcat8.5 installation directory (hereinafter referred to as CATALINA_HOME defined in the environment variable following the Tomcat startup bat | sh file). Place the following three.

2. Place the log4j2 configuration file (log4j2.xml or log4j2.yml)

Create a Log4j2 configuration file (usually log4j2.xml) and place it. You can place it anywhere, but for the sake of clarity, place it in CATALINA_HOME / conf.

For a setting example of log4j2.xml, see Qiita: Steps to replace Tomcat log output with log4j2. Let's make appropriate adjustments.

3. Add the path to the log4j2 config file to the environment variable

The Tomcat startup files startup.bat and startup.sh are defined to execute setenv.bat and setenv.sh, which can define environment variables, so create these files **.

For Windows, write the following line

setenv.bat


SET JAVA_OPTS=%JAVA_OPTS% -Dlog4j.configurationFile=file://%CATALINA_HOME%/conf/log4j2.xml

That is all for the setting items. When you execute startup.bat or startup.sh, it will be output from Log4j2 safely.

What you should not do with the procedure that was effective up to Tomcat 8.0 series

Until Tomcat8.0 series, it was necessary to delete logging.properties in CATALINA_HOME / conf or save it to another location and download the adapter for log output separately, but these operations are no longer necessary. .. Rather ** Don't do ** (because log settings are ignored altogether)

References

Procedure to replace tomcat log output with log4j2 Log4J|Commons Logging Bridge http://tomcat.apache.org/download-80.cgi#8.5.15

Recommended Posts

Replaced Tomcat 8.5 log output with Log4j2.8 or later
Control log output with Doma2
Output embedded Tomcat access log to standard output with Spring Boot
Prepare for log output using log4j in Eclipse.
Format of the log output by Tomcat itself in Tomcat 8