<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div>Hi All, </div><div> </div><div>Subject: logback generates two log files</div><div>i am using Rollingfile appender and Time based rolling policy for one of the app., it generates two files one with the log file (sample.log) and the other with yesterday's date (sample-2014-07-27.0.log). Appreciate if anybody help on this.</div><div> </div><div><appender name="ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender"><br>  <if
 condition='property("logFolder").contains("log")'><br>   <then><br>    <file>${logFolder}/Sample/sample.log</file><br>   </then><br>   <else><br>    <file>sample.log</file><br>   </else><br>  </if><br>  <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><br>   <fileNamePattern>sreg-%d{yyyy-MM-dd}.%i.log</fileNamePattern><br>   <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"><br>    <!-- or whenever the file size reaches 50MB --><br>    <maxFileSize>50MB</maxFileSize><br>   </timeBasedFileNamingAndTriggeringPolicy> <br>  </rollingPolicy>
 <br>  <encoder><br>   <pattern>[%d{ISO8601}] [%-18thread]  - %-25c{0}  - %-5p - %msg%n</pattern><br>  </encoder><br> </appender> </div> <div class="qtdSeparateBR"><br><br></div><div style="display: block;" class="yahoo_quoted"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> On Tuesday, July 8, 2014 7:48 AM, Jeremy Kane <jkane001@gmail.com> wrote:<br> </font> </div>  <br><br> <div><div id="yiv1724034110"><div dir="ltr">That did the trick,  thanks! </div>
<div>On May 27, 2014 2:09 AM, "Tony Trinh" <<a href="mailto:tony19@gmail.com" rel="nofollow" target="_blank" ymailto="mailto:tony19@gmail.com">tony19@gmail.com</a>> wrote:<br><blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;">
<div dir="ltr">Hello Jeremy,<div><br></div><div>You mention a size-based policy, but I only see a time-based policy in your config.</div><div><br></div><div>The following patterns should work for RollingFileAppender. The code snippets are based on the code you pasted, and I did not test them. Please let me know if they work for you.</div>


<div><br></div><div>-Tony</div><div><br></div><div><b>Size-and-time-based rollover [1]</b><br></div><div><div><ul><li>rolling policy = <font face="courier new, monospace">new TimeBasedRollingPolicy()</font><br></li><ul><li>


TimeBasedRollingPolicy.timeBasedFileNamingAndTriggeringPolicy = <font face="courier new, monospace">new SizeAndTimeBasedFNATP()</font></li></ul><li>trigger policy = do not set (already handled by TimeBasedRollingPolicy)</li>


</ul></div></div><div>Code:</div><div><br></div><div><div><font face="courier new, monospace">    TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();</font></div>


<div><font face="courier new, monospace">    rollingPolicy.setMaxHistory(2);</font></div><div><font face="courier new, monospace">    rollingPolicy.setFileNamePattern(fileDirectory + "/log.%d.txt");</font></div>


<div><font face="courier new, monospace">    rollingPolicy.setParent(rollingFileAppender);</font></div><div><font face="courier new, monospace">    rollingPolicy.setContext(loggerContext);</font></div><div><font face="courier new, monospace"><br>


</font></div><div><font face="courier new, monospace">    // size-and-time-based rollover (5MB files).</font></div><div><font face="courier new, monospace">    // We don't need to set this triggering policy's context or start</font></div>


<div><font face="courier new, monospace">    // it because RollingFileAppender.start() does all that for us.</font></div><div><font face="courier new, monospace">    // SizeAndTimeBasedFNATP.start() is relatively expensive, so do it</font></div>


<div><font face="courier new, monospace">    // only once if we can avoid it.</font></div><div><font face="courier new, monospace">    SizeAndTimeBasedFNATP<ILoggingEvent> triggerPolicy = new SizeAndTimeBasedFNATP<ILoggingEvent>();</font></div>


<div><font face="courier new, monospace">    triggerPolicy.setMaxFileSize("5MB");</font></div><div><font face="courier new, monospace">    rollingPolicy.setTimeBasedFileNamingAndTriggeringPolicy(triggerPolicy);</font></div>


</div><div><font face="courier new, monospace"><br></font></div><div><font face="courier new, monospace">    rollingPolicy.start();</font></div><div><font face="courier new, monospace"><br></font></div><div><div><b>Size-based rollover [2]</b></div>


<div><ul><li>rolling policy = <font face="courier new, monospace">new FixedWindowRollingPolicy()</font><br></li><li>trigger policy = <font face="courier new, monospace">new SizeBasedTriggeringPolicy()</font></li></ul></div>


</div><div>Code:<br></div><div><br></div><div><div><font face="courier new, monospace">    // size-based rollover (fixed window of 3 files, 5MB each)</font></div><div><font face="courier new, monospace">    FixedWindowRollingPolicy rollingPolicy2 = new FixedWindowRollingPolicy();</font></div>


<div><font face="courier new, monospace">    rollingPolicy2.setContext(loggerContext);</font></div><div><font face="courier new, monospace">    rollingPolicy2.setFileNamePattern("foo.%i.log");</font></div><div>

<font face="courier new, monospace">    rollingPolicy2.setMinIndex(1);</font></div>
<div><font face="courier new, monospace">    rollingPolicy2.setMaxIndex(3);</font></div><div><font face="courier new, monospace">    rollingPolicy2.start();</font></div><div><font face="courier new, monospace"><br></font></div>


<div><font face="courier new, monospace">    // size-based rollover needs a triggering policy</font></div><div><font face="courier new, monospace">    SizeBasedTriggeringPolicy<ILoggingEvent> triggerPolicy2 = new SizeBasedTriggeringPolicy<ILoggingEvent>();</font></div>


<div><font face="courier new, monospace">    triggerPolicy2.setContext(loggerContext);</font></div><div><font face="courier new, monospace">    triggerPolicy2.setMaxFileSize("5MB");</font></div><div><font face="courier new, monospace">    triggerPolicy2.start();</font></div>


</div><div><br></div><div><br></div><div>[1] <a href="http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP" rel="nofollow" target="_blank">http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP</a></div><div>[2] <a href="http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy" rel="nofollow" target="_blank">http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy</a></div>


<div><br></div></div><div><br><br><div>On Wed, May 14, 2014 at 8:53 PM, Jeremy Kane <span dir="ltr"><<a href="mailto:jkane001@gmail.com" rel="nofollow" target="_blank" ymailto="mailto:jkane001@gmail.com">jkane001@gmail.com</a>></span> wrote:<br>


<blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><div dir="ltr">I've been trying to get the rollinglogfileappender to roll-over at a certain file size, but I've had no luck.  I can get it to roll over at midnight each night, but I still would prefer to either combine them or have it just be file-size limited.<div>




<br></div><div>My config is such:</div><div><br></div><div><div>// Rolling Log Appender</div><div><span style="white-space: pre-wrap;">               </span>String fileDirectory = KanetikApplication.getFileDirectory(context);</div>
<div>
<br></div><div><span style="white-space: pre-wrap;">          </span>RollingFileAppender<ILoggingEvent> rollingFileAppender = new RollingFileAppender<ILoggingEvent>();</div><div><span style="white-space: pre-wrap;">         </span>rollingFileAppender.setContext(loggerContext);</div>




<div><span style="white-space: pre-wrap;">                </span>rollingFileAppender.setAppend(true);</div><div><span style="white-space: pre-wrap;">           </span>rollingFileAppender.setFile(fileDirectory + "/log.txt");</div>
<div>
<br></div><div><span style="white-space: pre-wrap;">          </span>TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new TimeBasedRollingPolicy<ILoggingEvent>();</div><div><span style="white-space: pre-wrap;">         </span>rollingPolicy.setMaxHistory(2);</div>




<div><span style="white-space: pre-wrap;">                </span>rollingPolicy.setFileNamePattern(fileDirectory + "/log.%d.txt");</div><div><span style="white-space: pre-wrap;">             </span>rollingPolicy.setParent(rollingFileAppender);</div>




<div><span style="white-space: pre-wrap;">                </span>rollingPolicy.setContext(loggerContext);</div><div><span style="white-space: pre-wrap;">               </span></div><div><span style="white-space: pre-wrap;">               </span>rollingPolicy.start();</div>




<div><br></div><div><span style="white-space: pre-wrap;">               </span>rollingFileAppender.setRollingPolicy(rollingPolicy);</div><div><br></div><div><span style="white-space: pre-wrap;">          </span>PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();</div>




<div><span style="white-space: pre-wrap;">                </span>fileEncoder.setContext(loggerContext);</div><div><span style="white-space: pre-wrap;">         </span>fileEncoder.setPattern("%d{h:mm:ss} %level - %msg%n");</div>
<div>
<span style="white-space: pre-wrap;">           </span>fileEncoder.start();</div><div><br></div><div><span style="white-space: pre-wrap;">          </span>rollingFileAppender.setEncoder(fileEncoder);</div><div><span style="white-space: pre-wrap;">           </span>rollingFileAppender.start();</div>




<div><br></div><div><span style="white-space: pre-wrap;">               </span>// LogCat Appender</div><div><span style="white-space: pre-wrap;">             </span>PatternLayoutEncoder logcatEncoder = new PatternLayoutEncoder();</div><div>
<span style="white-space: pre-wrap;">           </span>logcatEncoder.setContext(loggerContext);</div>
<div><span style="white-space: pre-wrap;">                </span>logcatEncoder.setPattern("%msg%n");</div><div><span style="white-space: pre-wrap;">          </span>logcatEncoder.start();</div><div><br></div><div><span style="white-space: pre-wrap;">                </span>PatternLayoutEncoder tagEncode = new PatternLayoutEncoder();</div>




<div><span style="white-space: pre-wrap;">                </span>tagEncode.setContext(loggerContext);</div><div><span style="white-space: pre-wrap;">           </span>tagEncode.setPattern(tag);</div><div><span style="white-space: pre-wrap;">             </span>tagEncode.start();</div>




<div><br></div><div><span style="white-space: pre-wrap;">               </span>LogcatAppender logcatAppender = new LogcatAppender();</div><div><span style="white-space: pre-wrap;">          </span>logcatAppender.setContext(loggerContext);</div>

<div><span style="white-space: pre-wrap;">                </span>logcatAppender.setEncoder(logcatEncoder);</div><div><span style="white-space: pre-wrap;">              </span>logcatAppender.setTagEncoder(tagEncode);</div><div><span style="white-space: pre-wrap;">               </span>logcatAppender.start();</div>




<div><br></div><div><span style="white-space: pre-wrap;">               </span>// add the newly created appenders to the root logger;</div><div><span style="white-space: pre-wrap;">         </span>// qualify Logger to disambiguate from org.slf4j.Logger</div>




<div><span style="white-space: pre-wrap;">                </span>ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);</div><div><br></div><div><span style="white-space: pre-wrap;">                </span>root.setLevel(level);</div>




<div><span style="white-space: pre-wrap;">                </span>root.addAppender(rollingFileAppender);</div><div><span style="white-space: pre-wrap;">         </span>root.addAppender(logcatAppender);</div></div><div><br></div><div>Can anyone tell me why it's not working?</div>




<div><br></div><div>Thanks!</div><span><font color="#888888"><div>J</div></font></span></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" rel="nofollow" target="_blank" ymailto="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div><br></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="mailto:Logback-user@qos.ch" rel="nofollow" target="_blank" ymailto="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br>
<a href="http://mailman.qos.ch/mailman/listinfo/logback-user" rel="nofollow" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br></blockquote></div></div><br>_______________________________________________<br>Logback-user mailing list<br><a href="mailto:Logback-user@qos.ch" ymailto="mailto:Logback-user@qos.ch">Logback-user@qos.ch</a><br><a href="http://mailman.qos.ch/mailman/listinfo/logback-user" target="_blank">http://mailman.qos.ch/mailman/listinfo/logback-user</a><br><br></div>  </div> </div>  </div> </div></body></html>