I am using Logback to create a daily rolling log file.  It does rename the existing log file and creates a new one, however it is not doing it correctly (or I am telling something incorrectly).  Below is the logback.xml file I am using:

 

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <timestamp key="today" datePattern="yyyyMMdd"/>

    <appender name="ScreenAppender" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>debug</level>
        </filter>
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} %-5level %logger{20} [%file:%line] - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="UpdateAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <append>true</append>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>info</level>
        </filter>
        <file>${CATALINA_HOME}/logs/update-server.log</file>
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} %-5level %logger{40} [%file:%line] - %msg%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>update-server.%d{yyyy-MM-dd}.zip</fileNamePattern>
            <maxHistory>180</maxHistory>
        </rollingPolicy>
    </appender>

    <root level="debug">
        <appender-ref ref="ScreenAppender"/>
        <appender-ref ref="UpdateAppender"/>
    </root>
</configuration>

 

The log file does get created as update-server.log.  And when the day rolls over, the next generated message for logging does result in that log file being renamed, but not as I expect it to.  The resulting name is update-server.log1161295506996864.tmp.  And, the file itself is not ZIPped, just renamed.

 

I would expect the file to be named  update-server.20120103.log and to have that file ZIPped.  Does anyone know why?

 

As a second (minor) issue, I would like the original log file to be called update-server-YYYYMMDD.log, but when I tried to do that, the log file created stays the same and at midnight, the file is overwritten.  I used the line below, but it appears that Logback does not increment the ${today} value:

 

        <file>${CATALINA_HOME}/logs/update-server-${today}.log</file>

 

Mike Viens
Sr. Software Engineer
K-12 Technology


10911 White Rock Road, Suite 100

Rancho Cordova, CA 95670

 

D: (916)288-1651

M: (916)524-3663

E: mike.viens@pearson.com


Pearson
Always Learning
Learn more at
www.pearsonschoolsystems.com