Mittwoch, 14. März 2012

How to configure tomcat to use slf4j and logback

This section explains how to configure Tomcat to use slf4j rather than java.util.logging for all Tomcat's internal logging.

First of all it is nothing special because it will use the log4j over slf4 and logback.

  1. Download tomcat-juli.jar and tomcat-juli-adapters.jar that are available as an "extras" component for Tomcat. See Additional Components documentation for details.

  2. Put the following jars into $CATALINA_HOME/lib.

    • log4j-over-slf4j-1.6.4.jar

    • logback-classic-1.0.0.jar

    • logback-core-1.0.0.jar

    • slf4j-api-1.6.4.jar

    • tomcat-juli-adapters.jar

  3. Replace $CATALINA_HOME/bin/tomcat-juli.jar with tomcat-juli.jar from "extras"

  4. Delete $CATALINA_BASE/conf/ to prevent java.util.logging generating zero length log files.

  5. Add logback.xml into $CATALINA_HOME/lib.

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are assigned the type
    ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
    <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    <pattern>%d{HH:mm:ss.SSS} %-5level %logger{50} - %msg%n</pattern>

    <root level="INFO">
    <appender-ref ref="STDOUT" />

Keine Kommentare:

Kommentar veröffentlichen