<div dir="ltr"><div class="" style="font-size:14px;font-family:'Open Sans',sans-serif;margin:0px;padding:0px;line-height:22px">Hi logback geeks,</div><div class="" style="font-size:14px;font-family:'Open Sans',sans-serif;margin:0px;padding:0px;line-height:22px"><br></div><div class="" style="font-size:14px;font-family:'Open Sans',sans-serif;margin:0px;padding:0px;line-height:22px">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"><br style="font-family:inherit">Following are the sample logging file names<br style="font-family:inherit"><br style="font-family:inherit">20150515_1_Job1.log<br style="font-family:inherit">20150515_2_Job1.log<br style="font-family:inherit"><br style="font-family:inherit">For the above scenario we are using the following logback configuration.<br style="font-family:inherit"></div><br><div><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre;background-color:rgb(249,251,253)"><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></div><div><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre;background-color:rgb(249,251,253)"><br></span></div><div><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">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;background-color:rgb(249,251,253)"><br></span></div><div><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px"><br></span></div><div><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre;background-color:rgb(249,251,253)">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"><br></span></div><div><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre;background-color:rgb(249,251,253)"><br></span></div><div><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">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"><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px"><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">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"><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px"><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">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"><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px"><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">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"><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px"><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">Regards,</span><br style="font-size:14px;font-family:'Open Sans',sans-serif;line-height:22px"><span style="font-family:'Open Sans',sans-serif;font-size:14px;line-height:22px">Mayuran</span><span style="color:rgb(11,55,77);font-family:Courier,monospace;font-size:11px;line-height:16px;white-space:pre;background-color:rgb(249,251,253)"><br></span></div></div>