[logback-user] Compression in SiftingAppender

ceki ceki at qos.ch
Sun Nov 6 08:01:22 CET 2011


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>
>   * 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>>
>           * 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


More information about the Logback-user mailing list