Search in sources :

Example 1 with TimeBasedTriggeringPolicy

use of org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy in project logging-log4j2 by apache.

the class AbstractLog4j2_1100Test method test.

@Test
public void test() {
    final Configuration configuration = context.getConfiguration();
    assertNotNull(configuration);
    final RollingFileAppender appender = configuration.getAppender("File");
    assertNotNull(appender);
    final CompositeTriggeringPolicy compositeTriggeringPolicy = appender.getTriggeringPolicy();
    assertNotNull(compositeTriggeringPolicy);
    final TriggeringPolicy[] triggeringPolicies = compositeTriggeringPolicy.getTriggeringPolicies();
    SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy = null;
    TimeBasedTriggeringPolicy timeBasedTriggeringPolicy = null;
    for (final TriggeringPolicy triggeringPolicy : triggeringPolicies) {
        if (triggeringPolicy instanceof TimeBasedTriggeringPolicy) {
            timeBasedTriggeringPolicy = (TimeBasedTriggeringPolicy) triggeringPolicy;
            assertEquals(7, timeBasedTriggeringPolicy.getInterval());
        }
        if (triggeringPolicy instanceof SizeBasedTriggeringPolicy) {
            sizeBasedTriggeringPolicy = (SizeBasedTriggeringPolicy) triggeringPolicy;
            assertEquals(100 * 1024 * 1024, sizeBasedTriggeringPolicy.getMaxFileSize());
        }
    }
    if (timeBasedTriggeringPolicy == null) {
        fail("Missing TimeBasedTriggeringPolicy");
    }
    if (sizeBasedTriggeringPolicy == null) {
        fail("Missing SizeBasedTriggeringPolicy");
    }
}
Also used : TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) Test(org.junit.Test)

Example 2 with TimeBasedTriggeringPolicy

use of org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy in project logging-log4j2 by apache.

the class Log4j1ConfigurationFactoryTest method testDailyRollingFileAppender.

private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
    final Configuration configuration = getConfiguration(configResource);
    final Appender appender = configuration.getAppender(name);
    assertNotNull(appender);
    assertEquals(name, appender.getName());
    assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
    final RollingFileAppender rfa = (RollingFileAppender) appender;
    assertEquals("target/hadoop.log", rfa.getFileName());
    assertEquals(filePattern, rfa.getFilePattern());
    final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
    assertNotNull(triggeringPolicy);
    assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
    final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
    final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
    assertEquals(1, triggeringPolicies.length);
    final TriggeringPolicy tp = triggeringPolicies[0];
    assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
    final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
    assertEquals(1, tbtp.getInterval());
    final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
    assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
    final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
    assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
    configuration.start();
    configuration.stop();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) NullAppender(org.apache.logging.log4j.core.appender.NullAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) Configuration(org.apache.logging.log4j.core.config.Configuration) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy) RolloverStrategy(org.apache.logging.log4j.core.appender.rolling.RolloverStrategy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)

Example 3 with TimeBasedTriggeringPolicy

use of org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy in project logging-log4j2 by apache.

the class AbstractLog4j1ConfigurationTest method testDailyRollingFileAppender.

private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws Exception {
    final Configuration configuration = getConfiguration(configResource);
    final Appender appender = configuration.getAppender(name);
    assertNotNull(appender);
    assertEquals(name, appender.getName());
    assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
    final RollingFileAppender rfa = (RollingFileAppender) appender;
    assertEquals("target/hadoop.log", rfa.getFileName());
    assertEquals(filePattern, rfa.getFilePattern());
    final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
    assertNotNull(triggeringPolicy);
    assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
    final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
    final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
    assertEquals(1, triggeringPolicies.length);
    final TriggeringPolicy tp = triggeringPolicies[0];
    assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
    final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
    assertEquals(1, tbtp.getInterval());
    final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
    assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
    final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
    assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
    configuration.start();
    configuration.stop();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) NullAppender(org.apache.logging.log4j.core.appender.NullAppender) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) Configuration(org.apache.logging.log4j.core.config.Configuration) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy) RolloverStrategy(org.apache.logging.log4j.core.appender.rolling.RolloverStrategy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) DefaultRolloverStrategy(org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)

Example 4 with TimeBasedTriggeringPolicy

use of org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy in project logging-log4j2 by apache.

the class MultipleTriggeringPolicyTest method assertBothTriggeringPoliciesConfigured.

void assertBothTriggeringPoliciesConfigured(final Configuration configuration) {
    final RollingFileAppender appender = configuration.getAppender("File");
    assertNotNull(appender);
    final CompositeTriggeringPolicy compositeTriggeringPolicy = appender.getTriggeringPolicy();
    assertNotNull(compositeTriggeringPolicy);
    final TriggeringPolicy[] triggeringPolicies = compositeTriggeringPolicy.getTriggeringPolicies();
    assertEquals(2, triggeringPolicies.length);
    final SizeBasedTriggeringPolicy sizeBasedTriggeringPolicy;
    final TimeBasedTriggeringPolicy timeBasedTriggeringPolicy;
    if (triggeringPolicies[0] instanceof SizeBasedTriggeringPolicy) {
        sizeBasedTriggeringPolicy = (SizeBasedTriggeringPolicy) triggeringPolicies[0];
        timeBasedTriggeringPolicy = (TimeBasedTriggeringPolicy) triggeringPolicies[1];
    } else {
        sizeBasedTriggeringPolicy = (SizeBasedTriggeringPolicy) triggeringPolicies[1];
        timeBasedTriggeringPolicy = (TimeBasedTriggeringPolicy) triggeringPolicies[0];
    }
    assertEquals(7, timeBasedTriggeringPolicy.getInterval());
    assertEquals(100 * 1024 * 1024, sizeBasedTriggeringPolicy.getMaxFileSize());
}
Also used : TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) RollingFileAppender(org.apache.logging.log4j.core.appender.RollingFileAppender) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy) CompositeTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy) TimeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy) SizeBasedTriggeringPolicy(org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy)

Aggregations

RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)4 CompositeTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy)4 SizeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy)4 TimeBasedTriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy)4 TriggeringPolicy (org.apache.logging.log4j.core.appender.rolling.TriggeringPolicy)4 Appender (org.apache.logging.log4j.core.Appender)2 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 NullAppender (org.apache.logging.log4j.core.appender.NullAppender)2 DefaultRolloverStrategy (org.apache.logging.log4j.core.appender.rolling.DefaultRolloverStrategy)2 RolloverStrategy (org.apache.logging.log4j.core.appender.rolling.RolloverStrategy)2 Configuration (org.apache.logging.log4j.core.config.Configuration)2 Test (org.junit.Test)1