This project is a solution for using SLF4J and Logback as Tomcat internal logging system.
This library is a re-packaged bundle of jcl-over-slf4j, SLF4J and Logback, highly inspirated by tomcat-slf4j-logback. This was done in the context of documenting the juli-to-slf4j bridge and its alternatives.
It builds an additional library that plugs into the tomcat-extras-juli “extra” component to provide SLF4J logging with the Logback backend, keeping the tomcat-extras-juli library separate, and unmodified. (Contrarily to tomcat-slf4j-logback, which retains only a portion of the default tomcat-juli in order to build a smaller library.)
This lib provides:
-
A JULI-dedicated bridge from the full JCL implementation of tomcat-extras-juli and a package-renamed SLF4J API.
-
Package-renamed SLF4J & Logback libraries, so that they might not conflict with any SLF4J & Logback that web applications may ship with.
Web applications that ship with their own SLF4J & Logback libraries will
properly create separate logging contexts. This is the
simple approach.
The configuration in conf/logback-catalina.xml
shall use the package-renamed
code, prepending com.apache.juli.
to all Logback class names.
JNDI
cannot be setup since Logback intializes before the Tomcat JNDI system is
ready.
The tomcat-extras-juli-over-slf4j.jar
must appear before the
tomcat-extras-juli.jar
on the $CLASSPATH
as detailed below. Indeed, the
default org.apache.juli.logging.LogFactory
is not suppressed from the
original tomcat-extras-juli.jar
. It is just masked by the one provided by
tomcat-extras-juli-over-slf4j.jar
. Any reason for a non-guraanteed classpath
order would result in a non-working system.
Running Tomcat with a security manager requires some more setup in
conf/catalina.policy
.
- Build the lib
mvn clean package
-
Copy the resulting
target/tomcat-extras-juli-over-slf4j-1.7.12.jar
to the$CATALINA_BASE/bin/
directory. -
Add the Bash code below to your
$CATALINA_BASE/bin/setenv.sh
script.
# Logging configuration
# Because the juli config needs to be set early at bootstrap time
# Deactivate standard JULI config (the correct way by Bugzilla #45585)
LOGGING_CONFIG="-Dnop"
# Add bridge to the class path
CLASSPATH="${CLASSPATH:+$CLASSPATH:}$CATALINA_BASE"/bin/tomcat-extras-juli-over-slf4j-1.7.12.jar
# Activate diagnostics in LogFactory of 'tomcat-extras-juli'
# Actually non are output because the original JULI LogFactory is masked
# by the one provided by 'juli-jcl-over-slf4j' above
CATALINA_OPTS="$CATALINA_OPTS -Dorg.apache.juli.logging.diagnostics.dest=STDOUT"
# Setup config file
CATALINA_OPTS="$CATALINA_OPTS -Djuli.logback.configurationFile=$CATALINA_BASE/conf/logback-catalina.xml"
-
Remove the default
$CATALINA_BASE/conf/logging.properties
because it's no use keeping it anymore. -
Restart Tomcat.
Copyright © 2015, Benjamin Gandon
The JULI-JCL-over-SLF4J library is released under the terms of the Apache 2.0 license, excepted some specific sub-components, as detailed in LICENSES.md.