views:

110

answers:

2

I've been trying to set up a simple logback project to roll my log files by date and by filesize, and so far I have been unable to get my appender to roll over to another file. Instead, it writes to the log specified by the <file/> tag.

Here is my logback.xml configuration file:

<?xml version="1.0"?>
<configuration scan="true" scanPeriod="10 seconds">
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
        </layout>
    </appender>

    <appender name="milliroller" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>log/output.log</file>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
        </layout>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>log/mylog-%d{yyyy-MM-dd}.%i.txt</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>1KB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="stdout"/>
        <appender-ref ref="milliroller"/>
    </root>

    <logger name="com.tkassembled.logback" level="DEBUG"/>
</configuration>

At first glance, it looks like it should work, right? Is there something I'm doing wrong? My entire, buildable project is available in a zip here: http://www.mediafire.com/file/2bxokkdyz2i/logback.zip

A: 

You should be able to set up your log using a FileHandler.

http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/FileHandler.html#FileHandler(java.lang.String, int, int)

This takes a file size limit and rotates the log when it hits that limit.

Freiheit
That's helpful but actually I'm looking for a solution within Logback. Logback is a great library and I'd love to use it, provided of course that I can get this up and going.
TK Kocheran
+1  A: 

This problem has been addressed and resolved on the logback-user mailing list.

Ceki