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:

  1. Creating a set of directories in catalina home named log4j2/lib and log4j2/conf.
  2. Placing log4j2-api-2.23.1.jar, log4j2-core-2.23.1.jar, and log4j2-appserver-2.23.1.jar in the log4j2/lib directory.
  3. 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.
  4. 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");