use of ch.qos.logback.core.rolling.RollingPolicy in project jmxtrans by jmxtrans.
the class TimeBasedRollingKeyOutWriter method initLogger.
@Override
protected Logger initLogger(String fileStr) throws IOException {
RollingPolicy rollingPolicy = initRollingPolicy(fileStr, getMaxLogBackupFiles(), getMaxLogFileSize());
RollingFileAppender appender = buildAppender(buildEncoder(), rollingPolicy);
rollingPolicy.start();
appender.start();
// configure the logger for info and add the appender
return getAndConfigureLogger(appender);
}
use of ch.qos.logback.core.rolling.RollingPolicy in project spring-boot by spring-projects.
the class LogbackConfigurationTests method customRollingFileNamePattern.
@Test
void customRollingFileNamePattern() throws JoranException {
JoranConfigurator configurator = new JoranConfigurator();
LoggerContext context = new LoggerContext();
configurator.setContext(context);
configurator.doConfigure(new File("src/test/resources/custom-file-log-pattern-with-fileNamePattern.xml"));
Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("FILE");
assertThat(appender).isInstanceOf(RollingFileAppender.class);
RollingPolicy rollingPolicy = ((RollingFileAppender<?>) appender).getRollingPolicy();
String fileNamePattern = ((SizeAndTimeBasedRollingPolicy<?>) rollingPolicy).getFileNamePattern();
assertThat(fileNamePattern).endsWith("my.log.%d{yyyyMMdd}.%i.gz");
}
use of ch.qos.logback.core.rolling.RollingPolicy in project qpid-broker-j by apache.
the class AppenderUtilsTest method testCreateRollingFileAppenderDailyRolling.
@Test
public void testCreateRollingFileAppenderDailyRolling() {
final RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
AppenderUtils.configureRollingFileAppender(_settings, new LoggerContext(), appender);
assertEquals("Unexpected appender file name", _testLogFileName, appender.getFile());
RollingPolicy rollingPolicy = appender.getRollingPolicy();
final boolean condition2 = rollingPolicy instanceof RollingPolicyDecorator;
assertTrue("Unexpected rolling policy", condition2);
rollingPolicy = ((RollingPolicyDecorator) rollingPolicy).getDecorated();
final boolean condition1 = rollingPolicy instanceof TimeBasedRollingPolicy;
assertTrue("Unexpected decorated rolling policy", condition1);
assertEquals("Unexpected max history", (long) MAX_HISTORY, (long) ((TimeBasedRollingPolicy) rollingPolicy).getMaxHistory());
assertEquals("Unexpected file name pattern", _testLogFileName + ".%d{yyyy-MM-dd}.%i.gz", ((TimeBasedRollingPolicy) rollingPolicy).getFileNamePattern());
assertEquals("Unexpected compression mode", CompressionMode.GZ, rollingPolicy.getCompressionMode());
TriggeringPolicy triggeringPolicy = ((TimeBasedRollingPolicy) rollingPolicy).getTimeBasedFileNamingAndTriggeringPolicy();
final boolean condition = triggeringPolicy instanceof AppenderUtils.DailyTriggeringPolicy;
assertTrue("Unexpected triggering policy", condition);
assertEquals("Unexpected triggering policy", String.valueOf(MAX_FILE_SIZE) + " MB", ((AppenderUtils.DailyTriggeringPolicy) triggeringPolicy).getMaxFileSize().toString());
assertEquals("Unexpected layout", LAYOUT, ((PatternLayoutEncoder) appender.getEncoder()).getPattern());
}
Aggregations