Application Server Integration
The Application Server module provides support for integrating Log4j into various Java Application Servers.
Apache Tomcat
Log4j may be used as the logging framework for Apache Tomcat. This support is implemented automatically by including the log4j-api, log4j-core, and log4j-appserver jars in the boot classpath. A file named log4j2-tomcat.xml, log4j2-tomcat.json, log4j2-tomcat.yaml, log4j2-tomcat.yml, or log4j2-tomcat.properties must also be placed in the boot classpath. This is most easily done by:
- Creating a set of directories in catalina home named log4j2/lib and log4j2/conf.
- Placing log4j2-api-2.21.0.jar, log4j2-core-2.21.0.jar, and log4j2-appserver-2.21.0.jar in the log4j2/lib directory.
- Creating a file named log4j2-tomcat.xml, log4j2-tomcat.json, log4j2-tomcat.yaml, log4j2-tomcat.yml, or log4j2-tomcat.properties in the log4j2/conf directory.
- Create or modify setenv.sh in the tomcat bin directory to include
CLASSPATH=$CATALINA_HOME/log4j2/lib/*:$CATALINA_HOME/log4j2/conf
Requirements
Requires Tomcat 8.5 or later.
Eclipse Jetty
Log4j may be used as the logging framework for Eclipse Jetty.
To direct Jetty to use this class, set the system property org.eclipse.jetty.util.log.class
to org.apache.logging.log4j.appserver.jetty.Log4j2Logger
.
From the command line with:
-Dorg.eclipse.jetty.util.log.class = org.apache.logging.log4j.appserver.jetty.Log4j2Logger
Programmatically with:
System.setProperty("org.eclipse.jetty.util.log.class", "org.apache.logging.log4j.appserver.jetty.Log4j2Logger");