<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">http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP</a></div><div>[2] <a href="http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy">http://logback.qos.ch/manual/appenders.html#SizeBasedTriggeringPolicy</a></div>

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

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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 class="HOEnZb"><font color="#888888"><div>J</div></font></span></div>
<br>_______________________________________________<br>
Logback-user mailing list<br>
<a href="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></blockquote></div><br></div>