[logback-user] Compression in SiftingAppender

TJ Rothwell tj.rothwell at gmail.com
Sun Nov 6 17:26:50 CET 2011


This direction seems a bit clunky, as I'm duplicating code. What if
RollingFileAppender knew to close/roll?

So a new method in RollingPolicy like 'isTriggeringEvent', but
'isTriggeringOnClose'. The base class would return false so existing impl's
aren't affected.

Now RollingFileAppender is back in the driver's seat to control the roll at
close.

If RollingFileAppender doesn't have file set and is using a RollingPolicy
using the '%i' in the file pattern, the active file on close would never be
compressed. This case could be resolved by returning true for
isTriggeringOnClose.

-- TJ
On Sun, Nov 6, 2011 at 1:01 AM, ceki <ceki at qos.ch> wrote:

>
> I have not looked at your code very carefully but it seems that your
> life would be easier if the stop() method in RollingFileAppender would
> be changed from
>
> public void stop() {
>  if(rollingPolicy != null) rollingPolicy.stop();
>  if(triggeringPolicy != null) triggeringPolicy.stop();
>  super.stop();
> }
>
> to
>
> public void stop() {
>  super.stop();
>  if(rollingPolicy != null) rollingPolicy.stop();
>  if(triggeringPolicy != null) triggeringPolicy.stop();
> }
>
> or even better to
>
> public void stop() {
>  super.stop();
>  rollingPolicy.stop();
>  if(rollingPolicy != triggeringPolicy)
>    triggeringPolicy.stop();
> }
>
> Let me know if the above change in RollingFileAppender's stop() method
> helps and if it does, then let me know and I'll do the necessary
> changes.
>
>
> On 11/5/2011 11:46 PM, TJ Rothwell wrote:
>
>> I've updated my github with an implementation that works when the for my
>> circumstance (compression & no file in appender).
>>
>>  * CloseTBRP.java
>> <https://github.com/trothwell/**logback-test/blob/master/src/**
>> main/java/org/trothwell/**lbtest/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<https://github.com/trothwell/logback-test/blob/master/src/test/java/org/trothwell/lbtest/TestCloseTBRP.java>
>> >
>>
>> I didn't see a way to close the parent appender's outputstream from my
>> RollingPolicy. I might have to subclass RollingFileAppender to make this
>> solution production ready.
>>
>> I also noted a few other concerns I have in the comments--look for //
>> FIXME's.
>>
>> -- TJ
>>
>> On Fri, Nov 4, 2011 at 7:06 AM, ceki <ceki at qos.ch <mailto:ceki at qos.ch>>
>>
>> wrote:
>>
>>
>>    I don't think rollover() should be invoked within the close()
>>    method. You rather want to close the file and than compress it.
>>
>>    The compression goes something like:
>>
>>      if (compressionMode == CompressionMode.NONE) {
>>         // nothing to do?
>>      } else {
>>        if (getParentsRawFileProperty() == null) {
>>          asyncCompress(__**elapsedPeriodsFileName,
>> elapsedPeriodsFileName,
>>                        elpasedPeriodStem);
>>        } else {
>>          renamedRawAndAsyncCompress(__**elapsedPeriodsFileName,
>>
>>                                     elpasedPeriodStem);
>>        }
>>      }
>>
>>    See the rollover() method in TimeBasedRollingPolicy. I'll have
>>    another look at all this tomorrow.
>>
>>    Cheers,
>>
>>    --
>>    Ceki
>>    http://twitter.com/#!/ceki
>>
>>
>>    On 05/11/2011 12:30 AM, TJ Rothwell wrote:
>>
>>        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<https://github.com/trothwell/__logback-test/blob/master/src/__main/java/org/trothwell/__lbtest/CloseTBRP.java>
>>        <https://github.com/trothwell/**logback-test/blob/master/src/**
>> main/java/org/trothwell/**lbtest/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<https://github.com/trothwell/__logback-test/blob/master/src/__test/java/org/trothwell/__lbtest/TestCloseTBRP.java>
>>
>>        <https://github.com/trothwell/**logback-test/blob/master/src/**
>> test/java/org/trothwell/**lbtest/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
>>
>>
>
>
> --
> 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/20111106/bcc95a25/attachment-0001.html>


More information about the Logback-user mailing list