use of ch.qos.logback.core.rolling.FixedWindowRollingPolicy in project sling by apache.
the class TestLogWriter method testSizeBasedLegacyPattern.
@Test
public void testSizeBasedLegacyPattern() {
LogWriter lw = new LogWriter("foo", "target/foo", 5, "4k");
Appender<ILoggingEvent> a = createappender(lw);
assertInstanceOf(a, SlingRollingFileAppender.class);
SlingRollingFileAppender sr = (SlingRollingFileAppender) a;
assertInstanceOf(sr.getTriggeringPolicy(), SizeBasedTriggeringPolicy.class);
assertInstanceOf(sr.getRollingPolicy(), FixedWindowRollingPolicy.class);
SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) sr.getTriggeringPolicy();
FixedWindowRollingPolicy fwRp = (FixedWindowRollingPolicy) sr.getRollingPolicy();
assertEquals(5, fwRp.getMaxIndex());
assertEquals(String.valueOf(4 * FileUtils.ONE_KB), sbtp.getMaxFileSize());
}
use of ch.qos.logback.core.rolling.FixedWindowRollingPolicy in project bitsquare by bitsquare.
the class Log method setup.
public static void setup(String fileName) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
RollingFileAppender appender = new RollingFileAppender();
appender.setContext(loggerContext);
appender.setFile(fileName + ".log");
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(loggerContext);
rollingPolicy.setParent(appender);
rollingPolicy.setFileNamePattern(fileName + "_%i.log");
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(10);
rollingPolicy.start();
triggeringPolicy = new SizeBasedTriggeringPolicy();
triggeringPolicy.setMaxFileSize(FileSize.valueOf("10MB"));
triggeringPolicy.start();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%d{MMM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{15}: %msg %xEx%n");
encoder.start();
appender.setEncoder(encoder);
appender.setRollingPolicy(rollingPolicy);
appender.setTriggeringPolicy(triggeringPolicy);
appender.start();
logbackLogger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logbackLogger.addAppender(appender);
logbackLogger.setLevel(Level.INFO);
// log errors in separate file
// not working as expected still.... damn logback...
/* FileAppender errorAppender = new FileAppender();
errorAppender.setEncoder(encoder);
errorAppender.setName("Error");
errorAppender.setContext(loggerContext);
errorAppender.setFile(fileName + "_error.log");
LevelFilter levelFilter = new LevelFilter();
levelFilter.setLevel(Level.ERROR);
levelFilter.setOnMatch(FilterReply.ACCEPT);
levelFilter.setOnMismatch(FilterReply.DENY);
levelFilter.start();
errorAppender.addFilter(levelFilter);
errorAppender.start();
logbackLogger.addAppender(errorAppender);*/
}
Aggregations