I've updated my github with an implementation that works when the for my circumstance (compression & no file in appender).<div><br></div><div><div> * <a href="https://github.com/trothwell/logback-test/blob/master/src/main/java/org/trothwell/lbtest/CloseTBRP.java">CloseTBRP.java</a></div>
<div><span style="background-color: transparent; "> * </span><a href="https://github.com/trothwell/logback-test/blob/master/src/test/java/org/trothwell/lbtest/TestCloseTBRP.java" style="background-color: transparent; ">TestCloseTBRP.java</a></div>
<div><br></div><div>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.</div><div><br></div><div>
I also noted a few other concerns I have in the comments--look for // FIXME's.</div><div><br></div></div><div>-- TJ<br><br><div class="gmail_quote">On Fri, Nov 4, 2011 at 7:06 AM, ceki <span dir="ltr"><<a href="mailto:ceki@qos.ch">ceki@qos.ch</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
I don't think rollover() should be invoked within the close() method. You rather want to close the file and than compress it.<br>
<br>
The compression goes something like:<br>
<br>
if (compressionMode == CompressionMode.NONE) {<br>
// nothing to do?<br>
} else {<br>
if (getParentsRawFileProperty() == null) {<br>
asyncCompress(<u></u>elapsedPeriodsFileName, elapsedPeriodsFileName,<br>
elpasedPeriodStem);<br>
} else {<br>
renamedRawAndAsyncCompress(<u></u>elapsedPeriodsFileName,<br>
elpasedPeriodStem);<br>
}<br>
}<br>
<br>
See the rollover() method in TimeBasedRollingPolicy. I'll have another look at all this tomorrow.<br>
<br>
Cheers,<br>
<br>
-- <br>
Ceki<br>
<a href="http://twitter.com/#!/ceki" target="_blank">http://twitter.com/#!/ceki</a><div class="im"><br>
<br>
On 05/11/2011 12:30 AM, TJ Rothwell wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
Ceki,<br>
<br>
So I gave it a shot.<br>
<br></div>
* CloseTBRP.java<br>
<<a href="https://github.com/trothwell/logback-test/blob/master/src/main/java/org/trothwell/lbtest/CloseTBRP.java" target="_blank">https://github.com/trothwell/<u></u>logback-test/blob/master/src/<u></u>main/java/org/trothwell/<u></u>lbtest/CloseTBRP.java</a>><br>
* TestCloseTBRP.java<br>
<<a href="https://github.com/trothwell/logback-test/blob/master/src/test/java/org/trothwell/lbtest/TestCloseTBRP.java" target="_blank">https://github.com/trothwell/<u></u>logback-test/blob/master/src/<u></u>test/java/org/trothwell/<u></u>lbtest/TestCloseTBRP.java</a>><div class="im">
<br>
<br>
I'm running into a few problems if you have some time to take a look:<br>
<br></div>
* I'm unable to delete files after stopping LoggerContext.<br>
* Output file count is off (SiftingAppender or RollingFileAppender<div class="im"><br>
doesn't create both output files)<br></div>
* NullPointerException occurs when stopping LoggerContext with<div class="im"><br>
CloseTBRP in use<br>
<br>
I have two scenarios.<br>
<br></div>
1. Create a normal TimeBasedRollingPolicy configured for compression<div class="im"><br>
that will create 2 output files.<br></div>
2. Create the new auto-close CloseTBRP that will do the same.<div class="im"><br>
<br>
<br>
For both configurations this is the steps: (or look at unit test)<br>
<br></div>
1. Create new LoggerContext<br>
2. Configure LoggerContext<br>
3. Submit a log event<br>
4. Set MDC property for discriminator<br>
5. Submit a log event<br>
6. Stop LoggerContext<br>
7. Check log file counts<br>
1. for TBRP, 2 text files<br>
2. for CloseTBRP, 2 zip files<div class="im"><br>
<br>
<br>
Have a great weekend,<br>
-- TJ<br>
<br>
</div></blockquote><div class="HOEnZb"><div class="h5">
______________________________<u></u>_________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" target="_blank">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/<u></u>listinfo/logback-user</a><br>
</div></div></blockquote></div><br></div>