Logback roll only on file size
You want a SizeBasedTriggeringPolicy: http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy, probably combined with a FixedWindowRollingPolicy.
Was a comment before, not sure it deserves it's own answer, but here it is. ;)
Just to expand on sheltem's answer:
From my experiments, you have to use both a FixedWindowRollingPolicy
and a SizedBasedTriggeringPolicy
, as documented here. It appears that you can't use a SizedBasedTriggeringPolicy
with a SizeAndTimeBasedRollingPolicy
, for example: in my case logging then failed to happen.
Typical example in your xml file might be:
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>../logs/MyProject/testrolling.html</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>../logs/MyProject/backup%i.htm
</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>5MB</maxFileSize>
</triggeringPolicy>
<encoder class="...
Your backup files will then be called: backup1.htm, backup2.htm, etc.
It would appear that you cannot include a "%d" formatting directive in the fileNamePattern
: I tried and logging failed to happen. However, according to the documentation you must include the "%i" formatting directive, which makes sense.
much later
This may be me being naive, but I'd have thought a logging app should be designed to produce output by default, i.e. always interpret directives so that something at least is produced, rather than nothing.