[logback-user] Compression in SiftingAppender

ceki ceki at qos.ch
Fri Nov 4 15:59:43 CET 2011

Hi TJ,

It's a problem which has not been considered previously. Nice problem
description btw. One solution would be to subclass
TimeBasedRollingPolicy and override the stop() method so that it
compresses the current log file. It should not be too hard to do. Ask
for help if you run into trouble.

On 04/11/2011 3:32 PM, TJ Rothwell wrote:
> Hi,
> I'm using SiftingAppender on top of an appender that uses compression.
> When using a variable (like username) that will show up more than once,
> it works great. But when using a session id which is unique, then the
> log file will not be triggered for compression leading to larger disk
> usage. Is there a way to go about triggering the file to be compressed
> when the SiftingAppender closes the child appender after it's timeout
> period?
> Definition of my appender:
> <appender name="SIFT-SESSION_ID"
> class="ch.qos.logback.classic.sift.SiftingAppender">
> <discriminator class="ch.qos.logback.classic.sift.MDCBasedDiscriminator">
> <key>SESSION_ID</key>
> <defaultValue>unknown</defaultValue>
> </discriminator>
> <sift>
> <appender name="FILE-${SESSION_ID}"
> class="ch.qos.logback.core.rolling.RollingFileAppender">
> <encoder>
> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS zz} %-5level [%thread] %logger{35} -
> %msg%n%xEx{full}</pattern>
> </encoder>
> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
> <fileNamePattern>${CONTEXT_DATA_PATH}/logs/session/session-${SESSION_ID}.%d{yyyy-MM-dd}.%i.txt.zip</fileNamePattern>
> <timeBasedFileNamingAndTriggeringPolicy
> class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
> <maxFileSize>100MB</maxFileSize>
> </timeBasedFileNamingAndTriggeringPolicy>
> </rollingPolicy>
> </appender>
> </sift>
> </appender>
> Thanks!
> -- TJ


More information about the Logback-user mailing list