tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chris derham <>
Subject Re: Logging with slf4j in Tomcat 7
Date Fri, 06 May 2011 16:05:16 GMT
> In my application I use slf4j for logging.
> The logging messages appear in the console output like
> 17:05:31.985 ["http-bio-8080"-exec-1] DEBUG a.s.p.i.p.DefaultPersistence -
> 013.008: Daily plans (start)
> 17:05:31.985 ["http-bio-8080"-exec-1] DEBUG a.s.p.i.p.DefaultPersistence -
> session: null
> 17:05:31.986 ["http-bio-8080"-exec-1] ERROR a.s.p.i.p.DefaultPersistence -
> 013.009
> How can I configure Tomcat so that these log messages appear not only in
> console output, but also in a log file?
> This isn't a tomcat question - more a question on slf4j. You need to have
say slf4j-log4j12-X.Y.Z.jar packaged up in your. This will send slf4j
messages to log4j. Then configure log4j to send log messages to a file e.g.
create a file log4j.xml with something like this

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="">

    <appender name="FILE" class="org.apache.log4j.FileAppender">
        <param name="Threshold" value="DEBUG" />
        <param name="File" value="${catalina.base}/logs/yourApplication.log"
        <param name="Append" value="false" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %X{user} %-5p [%c]
%m%n" />

    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%p %X{user} -
%C{1}.%M(%L) | %m%n"/>

    <logger name="">
        <level value="DEBUG"/>

        <level value="DEBUG"/>
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message