<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Mayuran,<div class=""><br class=""></div><div class="">You can add FINALIZE_SESSION_MARKER to the MDC to trigger the sub-appender to be cleaned up.  This is documented in <a href="http://logback.qos.ch/manual/appenders.html" class="">http://logback.qos.ch/manual/appenders.html</a></div><div class=""><br class=""></div><div class="">Once you do that the sub-appender goes into lingering state for 10 seconds, then the appender will be closed after that.</div><div class=""><br class=""></div><div class="">Dave</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 17 May 2015, at 10:50, mayuran satchithanantham <<a href="mailto:mayuran19@gmail.com" class="">mayuran19@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi David, <div class=""><br class=""></div><div class="">Thanks for the prompt reply.</div><div class="">If you remember the way to trigger the closing of appender, please let me know.</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Mayuran</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, May 17, 2015 at 5:46 PM, David Roussel <span dir="ltr" class=""><<a href="mailto:nabble@diroussel.xsmail.com" target="_blank" class="">nabble@diroussel.xsmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Hi Mayuran,</div><div class=""><br class=""></div><div class="">The logic controlling this is in ch.qos.logback.core.sift.AppenderTracker I seem to remember I’ve had problems with this in the past, but I don’t remember the details now.  It’s controlled by a timeout.  Maybe there should be an explicit way to trigger the closing of an appender controlled by the sifting logic.</div><div class=""><br class=""></div><div class="">David</div><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On 17 May 2015, at 09:44, mayuran satchithanantham <<a href="mailto:mayuran19@gmail.com" target="_blank" class="">mayuran19@gmail.com</a>> wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class=""><div style="font-size:14px;font-family:'Open Sans',sans-serif;margin:0px;padding:0px;line-height:22px" class="">Hi logback geeks,</div><div style="font-size:14px;font-family:'Open Sans',sans-serif;margin:0px;padding:0px;line-height:22px" class=""><br class=""></div><div style="font-size:14px;font-family:'Open Sans',sans-serif;margin:0px;padding:0px;line-height:22px" class="">We are using logback "SiftingAppender" for generating the log files based on the date and other information such as cycle(Each date can have multiple cycles).<br style="font-family:inherit" class=""><br style="font-family:inherit" class="">Following are the sample logging file names<br style="font-family:inherit" class=""><br style="font-family:inherit" class="">20150515_1_Job1.log<br style="font-family:inherit" class="">20150515_2_Job1.log<br style="font-family:inherit" class=""><br style="font-family:inherit" class="">For the above scenario we are using the following logback configuration.<br style="font-family:inherit" class=""></div><br class=""><div class=""><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,251,253)" class=""><appender name="BATCH_LOGGER_APPENDER" class="ch.qos.logback.classic.sift.SiftingAppender">
    <discriminator>
        <key>batchLoggerFileName</key>
        <defaultValue>unknown</defaultValue>
    </discriminator>
    <sift>
        <appender class="ch.qos.logback.core.FileAppender">
            <file>${batchlog.dir}/${batchLoggerFileName}.log</file>
            <layout class="ch.qos.logback.classic.PatternLayout">
                <pattern>%d{yyyy-MM-dd_HH:mm:ss.SSS} | %-5level | [%thread] | %msg%n%rEx</pattern>
            </layout>
        </appender>
    </sift>
</appender>

<logger name="BATCH_LOGGER" level="INFO" additivity="false">
    <appender-ref ref="BATCH_LOGGER_APPENDER"></appender-ref>
</logger></span><br class=""></div><div class=""><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,251,253)" class=""><br class=""></span></div><div class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">Following is the java code for logging the details to the specific logs files.</span><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,251,253)" class=""><br class=""></span></div><div class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class=""><br class=""></span></div><div class=""><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,251,253)" class="">private static final Logger BATCH_LOGGER = LoggerFactory
        .getLogger("BATCH_LOGGER");

public void info(JobInfo jobInfo, String message) {
    MDC.put("batchLoggerFileName", jobInfo.getJobId());
    BATCH_LOGGER.info(message);
    MDC.remove("batchLoggerFileName");
}</span><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class=""><br class=""></span></div><div class=""><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,251,253)" class=""><br class=""></span></div><div class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">We have some other jobs that do the housekeeping of the old log files with the retention of 2 days(Two day old files will be moved to another location).</span><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">But even after the job completes, we are not able to move the file. We suspect that logback is holding the resource and not letting the file to move or delete.</span><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">All the jobs are deployed in a single war file in apache tomcat 8 server.</span><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">Can anyone suggest how to enforce logback to release the resource after logging is completed?</span><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">Regards,</span><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px" class=""><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px" class="">Mayuran</span><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre-wrap;background-color:rgb(249,251,253)" class=""><br class=""></span></div></div></div></div>
_______________________________________________<br class="">Logback-user mailing list<br class=""><a href="mailto:Logback-user@qos.ch" target="_blank" class="">Logback-user@qos.ch</a><br class=""><a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank" class="">http://mailman.qos.ch/mailman/listinfo/logback-user</a></div></blockquote></div><br class=""></div><br class="">_______________________________________________<br class="">
Logback-user mailing list<br class="">
<a href="mailto:Logback-user@qos.ch" class="">Logback-user@qos.ch</a><br class="">
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank" class="">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">Logback-user mailing list<br class=""><a href="mailto:Logback-user@qos.ch" class="">Logback-user@qos.ch</a><br class="">http://mailman.qos.ch/mailman/listinfo/logback-user</div></blockquote></div><br class=""></div></body></html>