[logback-user] How to get rollingfileappender to roll over based on log size

Jeremy Kane jkane001 at gmail.com
Thu May 15 03:53:24 CEST 2014


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.

My config is such:

// Rolling Log Appender
String fileDirectory = KanetikApplication.getFileDirectory(context);

RollingFileAppender<ILoggingEvent> rollingFileAppender = new
RollingFileAppender<ILoggingEvent>();
rollingFileAppender.setContext(loggerContext);
 rollingFileAppender.setAppend(true);
rollingFileAppender.setFile(fileDirectory + "/log.txt");

TimeBasedRollingPolicy<ILoggingEvent> rollingPolicy = new
TimeBasedRollingPolicy<ILoggingEvent>();
rollingPolicy.setMaxHistory(2);
 rollingPolicy.setFileNamePattern(fileDirectory + "/log.%d.txt");
rollingPolicy.setParent(rollingFileAppender);
 rollingPolicy.setContext(loggerContext);
 rollingPolicy.start();

rollingFileAppender.setRollingPolicy(rollingPolicy);

PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
 fileEncoder.setContext(loggerContext);
fileEncoder.setPattern("%d{h:mm:ss} %level - %msg%n");
 fileEncoder.start();

rollingFileAppender.setEncoder(fileEncoder);
rollingFileAppender.start();

// LogCat Appender
PatternLayoutEncoder logcatEncoder = new PatternLayoutEncoder();
logcatEncoder.setContext(loggerContext);
 logcatEncoder.setPattern("%msg%n");
logcatEncoder.start();

PatternLayoutEncoder tagEncode = new PatternLayoutEncoder();
 tagEncode.setContext(loggerContext);
tagEncode.setPattern(tag);
tagEncode.start();

LogcatAppender logcatAppender = new LogcatAppender();
logcatAppender.setContext(loggerContext);
 logcatAppender.setEncoder(logcatEncoder);
logcatAppender.setTagEncoder(tagEncode);
logcatAppender.start();

// add the newly created appenders to the root logger;
// qualify Logger to disambiguate from org.slf4j.Logger
 ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger)
LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

root.setLevel(level);
 root.addAppender(rollingFileAppender);
root.addAppender(logcatAppender);

Can anyone tell me why it's not working?

Thanks!
J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20140514/45708128/attachment.html>


More information about the Logback-user mailing list