[logback-user] configuring logback to log to two different

Jason L. Buberel jason at buberel.org
Mon May 12 16:49:52 CEST 2008


Although I did see any particular error in your configuration, this is 
what we use in production, which logs content to either file 
(FILE_APPENDER) or console (CONSOLE_APPENDER) from many possible input 
LOGGERS.

In Java, we normally just use:

private static final Logger LOGGER = LoggerFactory.getLogger("general");

-jason

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false">
    <appender class="ch.qos.logback.core.ConsoleAppender" 
name="CONSOLE_APPENDER">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>OFF</level>
        </filter>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %t - %m%n</pattern>
        </layout>
    </appender>
    <appender name="FILE_APPENDER"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>/opt/tomcat/logs/debug.log</File>
        <rollingPolicy 
class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <FileNamePattern>/opt/tomcat/logs/debug.log.%i</FileNamePattern>
            <MinIndex>1</MinIndex>
            <MaxIndex>20</MaxIndex>
        </rollingPolicy>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>DEBUG</level>
        </filter>
        <triggeringPolicy 
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>500MB</MaxFileSize>
        </triggeringPolicy>
        <Append>true</Append>
        <Encoding>UTF-8</Encoding>
        <BufferedIO>false</BufferedIO>
        <ImmediateFlush>true</ImmediateFlush>

        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %C{1} %t - %m%n</pattern>
        </layout>
    </appender>
    <logger name="general">
        <level value="DEBUG"/>
        <appender-ref ref="FILE_APPENDER"/>
        <appender-ref ref="CONSOLE_APPENDER" />
    </logger>

    <logger name="sql-log" >
        <level value="OFF"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>


    <logger name="org.apache">
        <level value="ERROR"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>

    <logger name="org.hibernate.SQL" >
        <level value="OFF"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>

    <logger name="org.hibernate">
        <level value="OFF"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>


    <logger name="net.sf.jasperreports">
        <level value="OFF"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>
    <logger name="hivemind">
        <level value="ERROR"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>

    <logger name="tapestry">
        <level value="ERROR"/>
        <appender-ref ref="FILE_APPENDER"/>
    </logger>
</configuration>




More information about the Logback-user mailing list