Search in sources :

Example 26 with Appender

use of org.apache.logging.log4j.core.Appender 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 27 with Appender

use of org.apache.logging.log4j.core.Appender in project logging-log4j2 by apache.

the class Log4j1ConfigurationFactoryTest method testNullAppender.

@Test
public void testNullAppender() throws Exception {
    final Configuration configuration = getConfiguration("config-1.2/log4j-NullAppender.properties");
    final Appender appender = configuration.getAppender("NullAppender");
    assertNotNull(appender);
    assertEquals("NullAppender", appender.getName());
    assertTrue(appender.getClass().getName(), appender instanceof NullAppender);
}
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) Configuration(org.apache.logging.log4j.core.config.Configuration) NullAppender(org.apache.logging.log4j.core.appender.NullAppender) Test(org.junit.Test)

Example 28 with Appender

use of org.apache.logging.log4j.core.Appender in project logging-log4j2 by apache.

the class AbstractJpaAppenderTest method tearDown.

public void tearDown() throws SQLException {
    final LoggerContext context = LoggerContext.getContext(false);
    try {
        final Appender appender = context.getConfiguration().getAppender("databaseAppender");
        assertNotNull("The appender should not be null.", appender);
        assertTrue("The appender should be a JpaAppender.", appender instanceof JpaAppender);
        ((JpaAppender) appender).getManager().close();
    } finally {
        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
        context.reconfigure();
        StatusLogger.getLogger().reset();
        try (Statement statement = this.connection.createStatement()) {
            statement.execute("SHUTDOWN");
        }
        this.connection.close();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Statement(java.sql.Statement) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 29 with Appender

use of org.apache.logging.log4j.core.Appender in project logging-log4j2 by apache.

the class SyslogAppenderTestBase method removeAppenders.

protected void removeAppenders() {
    final Map<String, Appender> map = root.getAppenders();
    for (final Map.Entry<String, Appender> entry : map.entrySet()) {
        final Appender app = entry.getValue();
        root.removeAppender(app);
        app.stop();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Map(java.util.Map)

Example 30 with Appender

use of org.apache.logging.log4j.core.Appender in project logging-log4j2 by apache.

the class SocketAppenderTest method removeAndStopAppenders.

void removeAndStopAppenders() {
    final Map<String, Appender> map = logger.getAppenders();
    for (final Map.Entry<String, Appender> entry : map.entrySet()) {
        final Appender appender = entry.getValue();
        logger.removeAppender(appender);
        appender.stop();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Map(java.util.Map)

Aggregations

Appender (org.apache.logging.log4j.core.Appender)98 Test (org.junit.Test)50 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)25 Configuration (org.apache.logging.log4j.core.config.Configuration)21 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)18 LoggerContext (org.apache.logging.log4j.core.LoggerContext)15 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)13 Logger (org.apache.logging.log4j.Logger)12 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)12 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)11 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)9 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)9 Map (java.util.Map)8 Filter (org.apache.logging.log4j.core.Filter)8 AppenderControl (org.apache.logging.log4j.core.config.AppenderControl)8 URL (java.net.URL)7 IOException (java.io.IOException)5 LogEvent (org.apache.logging.log4j.core.LogEvent)5 Logger (org.apache.logging.log4j.core.Logger)5 AsyncAppender (org.apache.logging.log4j.core.appender.AsyncAppender)5