Search in sources :

Example 6 with RollingPolicy

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);
}
Also used : RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy)

Example 7 with RollingPolicy

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");
}
Also used : RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) SizeAndTimeBasedRollingPolicy(ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) SizeAndTimeBasedRollingPolicy(ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 8 with RollingPolicy

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());
}
Also used : RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) TriggeringPolicy(ch.qos.logback.core.rolling.TriggeringPolicy) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Test(org.junit.Test)

Aggregations

RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)8 RollingPolicy (ch.qos.logback.core.rolling.RollingPolicy)8 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 LoggerContext (ch.qos.logback.classic.LoggerContext)5 Test (org.junit.Test)4 Logger (ch.qos.logback.classic.Logger)3 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)3 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)2 SizeAndTimeBasedRollingPolicy (ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy)2 TriggeringPolicy (ch.qos.logback.core.rolling.TriggeringPolicy)2 GelfAppender (de.appelgriepsch.logback.GelfAppender)2 File (java.io.File)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Appender (ch.qos.logback.core.Appender)1 Encoder (ch.qos.logback.core.encoder.Encoder)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1