Logback Frequently Asked Questions
Logback Classic
- How can I use logback-classic with Jetty ?
- How does the automatic configuration work?
- How can I intercept JCL calls in Tomcat?
- How can I intercept JCL calls in Jetty ?
Logback Classic
- How can I use logback-classic with Jetty ?
-
The Jetty application server uses SLF4J for its internal logging. Here are the required steps to install logback as SLF4J's underlaying implementation.
A few jars must be present in the JETTY_HOME/lib directory.
Logback-classic is based on the SLF4J api. Therefore, the slf4j-api-VERSION.jar jar must be present. This jar can be downloaded from the SLF4J project.
Logback's own jars must also be present, namely logback-core-VERSION.jar and logback-classic-VERSION.jar .
To configure logback-classic, a file called logback.xml should be placed in the JETTY_HOME/resources directory. You can find configuration samples in the examples/src/chapter4/conf/ directory, in the distribution of logback.
[top]
- How does the automatic configuration work?
-
If a file called logback.xml is found in the classpath, then it is used.
In case it is not found, a logback-test.xml file is searched, and used if available.
If none of these files are available, logback uses its
BasicConfigurator
class to create a simple default configuration that will only log to the console.[top]
- How can I intercept JCL calls in Tomcat?
-
When a dependency of your webapp logs using Jakarta Commons Logging (for example Struts), you can intercept these calls and redirect them to logback.
This can be done by using jcl104-over-slf4j.jar , a module that is shipped with SLF4J .
If you have only one webapp, its WEB-INF/lib directory should already contain the logback jars, namely logback-core-VERSION.jar , logback-classic-VERSION.jar and slf4j-api-VERSION.jar . A logback configuration file, named logback.xml should be placed in the WEB-INF/classes/ directory.
You now need to add
jcl104-over-slf4j.jar
to your WEB-INF/lib directory and removecommons-logging-1.0.4.jar
. The logging that used to be directed to JCL should now be handled by logback.In case several webapps share the logback jars, you might place the previously mentionned jars in the common/lib/ directory of your Tomcat installation. The logback.xml file should then be placed in common/classes .
[top]
- How can I intercept JCL calls in Jetty ?
-
Using logback as the logging implementation of choice for frameworks depending on JCL can also be done in Jetty.
In case you have only one webapp, the required steps are exactly the same as those needed in Tomcat .
In case several webapps share the logback jars, you might place the necessary jars in the lib/ directory of your Jetty installation. The logback.xml file should then be placed in the resources/ directory.
However, due to Jetty's internal Classloading mechanism , the logback-classic-VERSION.jar and slf4j-api-VERSION.jar files should also be placed in the WEB-INF/lib/ directory of your webapps.
[top]