ch.qos.logback.core.rolling.RollingPolicy Java Examples

The following examples show how to use ch.qos.logback.core.rolling.RollingPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppenderUtilsTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #2
Source File: AppenderUtilsTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateRollingFileAppenderNonDailyRolling()
{
    when(_settings.isRollDaily()).thenReturn(Boolean.FALSE);
    when(_settings.isCompressOldFiles()).thenReturn(Boolean.FALSE);

    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 AppenderUtils.SimpleRollingPolicy;
    assertTrue("Unexpected decorated rolling policy", condition1);
    assertEquals("Unexpected max history",
                        (long) MAX_HISTORY,
                        (long) ((AppenderUtils.SimpleRollingPolicy) rollingPolicy).getMaxIndex());
    assertEquals("Unexpected file name pattern",
                        _testLogFileName + ".%i",
                        ((AppenderUtils.SimpleRollingPolicy) rollingPolicy).getFileNamePattern());
    assertEquals("Unexpected compression mode", CompressionMode.NONE, rollingPolicy.getCompressionMode());

    TriggeringPolicy triggeringPolicy = appender.getTriggeringPolicy();
    assertEquals("Unexpected triggering policy",
                        String.valueOf(MAX_FILE_SIZE) + " MB",
                        ((AppenderUtils.SizeTriggeringPolicy) triggeringPolicy).getMaxFileSize().toString());

    Encoder encoder = appender.getEncoder();
    final boolean condition = encoder instanceof PatternLayoutEncoder;
    assertTrue("Unexpected encoder", condition);
    assertEquals("Unexpected layout pattern", LAYOUT, ((PatternLayoutEncoder)encoder).getPattern());
}
 
Example #3
Source File: MultipleFileLogReader.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void setAppender(Appender<?> appender) {
	super.setAppender(appender);
	if (appender instanceof RollingFileAppender) {
		RollingPolicy rp = ((RollingFileAppender<?>) appender).getRollingPolicy();
		if (rp instanceof TimeBasedRollingPolicy) {
			fileNamePattern = ((TimeBasedRollingPolicy) rp).getFileNamePattern();
		} else {
			throw new UnsupportedOperationException("Must be TimeBasedRollingPolicy!");
		}
	} else {
		throw new RuntimeException("MultipleFileLogReader appender must be an instance of RollingFileAppender!");
	}
}