[logback-user] Compression in SiftingAppender

TJ Rothwell tj.rothwell at gmail.com
Sat Nov 5 00:30:38 CET 2011


Ceki,

So I gave it a shot.

   - CloseTBRP.java<https://github.com/trothwell/logback-test/blob/master/src/main/java/org/trothwell/lbtest/CloseTBRP.java>
   - TestCloseTBRP.java<https://github.com/trothwell/logback-test/blob/master/src/test/java/org/trothwell/lbtest/TestCloseTBRP.java>

I'm running into a few problems if you have some time to take a look:

   - I'm unable to delete files after stopping LoggerContext.
   - Output file count is off (SiftingAppender or RollingFileAppender doesn't
   create both output files)
   - NullPointerException occurs when stopping LoggerContext with CloseTBRP in
   use

I have two scenarios.

   1. Create a normal TimeBasedRollingPolicy configured for compression
   that will create 2 output files.
   2. Create the new auto-close CloseTBRP that will do the same.


For both configurations this is the steps: (or look at unit test)

   1. Create new LoggerContext
   2. Configure LoggerContext
   3. Submit a log event
   4. Set MDC property for discriminator
   5. Submit a log event
   6. Stop LoggerContext
   7. Check log file counts
      1. for TBRP, 2 text files
      2. for CloseTBRP, 2 zip files


Have a great weekend,
-- TJ

On Fri, Nov 4, 2011 at 9:59 AM, ceki <ceki at qos.ch> wrote:

> 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>
>> <**timeBasedFileNamingAndTriggeri**ngPolicy
>> class="ch.qos.logback.core.**rolling.SizeAndTimeBasedFNATP"**>
>> <maxFileSize>100MB</**maxFileSize>
>> </**timeBasedFileNamingAndTriggeri**ngPolicy>
>> </rollingPolicy>
>> </appender>
>> </sift>
>> </appender>
>>
>> Thanks!
>> -- TJ
>>
>
>
> --
> Ceki
> http://twitter.com/#!/ceki
> ______________________________**_________________
> Logback-user mailing list
> Logback-user at qos.ch
> http://mailman.qos.ch/mailman/**listinfo/logback-user<http://mailman.qos.ch/mailman/listinfo/logback-user>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20111104/14fd6df6/attachment.html>


More information about the Logback-user mailing list