<p>This direction seems a bit clunky, as I'm duplicating code. What if RollingFileAppender knew to close/roll?</p>
<p>So a new method in RollingPolicy like 'isTriggeringEvent', but 'isTriggeringOnClose'. The base class would return false so existing impl's aren't affected.</p>
<p>Now RollingFileAppender is back in the driver's seat to control the roll at close.</p>
<p>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.</p>
<p>-- TJ</p>
<div class="gmail_quote">On Sun, Nov 6, 2011 at 1:01 AM, ceki <span dir="ltr"><<a href="mailto:ceki@qos.ch" target="_blank">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 have not looked at your code very carefully but it seems that your<br>
life would be easier if the stop() method in RollingFileAppender would<br>
be changed from<br>
<br>
public void stop() {<br>
if(rollingPolicy != null) rollingPolicy.stop();<br>
if(triggeringPolicy != null) triggeringPolicy.stop();<br>
super.stop();<br>
}<br>
<br>
to<br>
<br>
public void stop() {<br>
super.stop();<br>
if(rollingPolicy != null) rollingPolicy.stop();<br>
if(triggeringPolicy != null) triggeringPolicy.stop();<br>
}<br>
<br>
or even better to<br>
<br>
public void stop() {<br>
super.stop();<br>
rollingPolicy.stop();<br>
if(rollingPolicy != triggeringPolicy)<br>
triggeringPolicy.stop();<br>
}<br>
<br>
Let me know if the above change in RollingFileAppender's stop() method<br>
helps and if it does, then let me know and I'll do the necessary<br>
changes.<div><br>
<br>
On 11/5/2011 11:46 PM, TJ Rothwell wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
I've updated my github with an implementation that works when the for my<br>
circumstance (compression & no file in appender).<br>
<br>
* CloseTBRP.java<br></div><div>
<<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>><br>
<br></div><div>
I didn't see a way to close the parent appender's outputstream from my<br>
RollingPolicy. I might have to subclass RollingFileAppender to make this<br>
solution production ready.<br>
<br>
I also noted a few other concerns I have in the comments--look for //<br>
FIXME's.<br>
<br>
-- TJ<br>
<br></div>
On Fri, Nov 4, 2011 at 7:06 AM, ceki <<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a> <mailto:<a href="mailto:ceki@qos.ch" target="_blank">ceki@qos.ch</a>>><div><br>
wrote:<br>
<br>
<br>
I don't think rollover() should be invoked within the close()<br>
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></div>
asyncCompress(__<u></u>elapsedPeriodsFileName, elapsedPeriodsFileName,<br>
elpasedPeriodStem);<br>
} else {<br>
renamedRawAndAsyncCompress(__<u></u>elapsedPeriodsFileName,<div><br>
elpasedPeriodStem);<br>
}<br>
}<br>
<br>
See the rollover() method in TimeBasedRollingPolicy. I'll have<br>
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><br>
<br>
<br>
On 05/11/2011 12:30 AM, TJ Rothwell wrote:<br>
<br>
Ceki,<br>
<br>
So I gave it a shot.<br>
<br>
* CloseTBRP.java<br></div>
<<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/<u></u>src/__main/java/org/trothwell/<u></u>__lbtest/CloseTBRP.java</a><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/<u></u>src/__test/java/org/trothwell/<u></u>__lbtest/TestCloseTBRP.java</a><div>
<div><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>>><br>
<br>
<br>
I'm running into a few problems if you have some time to take a<br>
look:<br>
<br>
* I'm unable to delete files after stopping LoggerContext.<br>
* Output file count is off (SiftingAppender or RollingFileAppender<br>
<br>
doesn't create both output files)<br>
* NullPointerException occurs when stopping LoggerContext with<br>
<br>
CloseTBRP in use<br>
<br>
I have two scenarios.<br>
<br>
1. Create a normal TimeBasedRollingPolicy configured for<br>
compression<br>
<br>
that will create 2 output files.<br>
2. Create the new auto-close CloseTBRP that will do the same.<br>
<br>
<br>
<br>
For both configurations this is the steps: (or look at unit test)<br>
<br>
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<br>
<br>
<br>
<br>
Have a great weekend,<br>
-- TJ<br>
<br>
</div></div></blockquote><span><font color="#888888">
<br>
<br>
<br>
-- <br>
Ceki<br>
<a href="http://twitter.com/#!/ceki" target="_blank">http://twitter.com/#!/ceki</a></font></span><div><div><br>
______________________________<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>