Search in sources :

Example 1 with Logger

use of org.apache.logging.log4j.core.Logger in project metrics by dropwizard.

the class InstrumentedAppenderConfigTest method canRecordError.

@Test
public void canRecordError() throws Exception {
    Logger logger = context.getLogger(this.getClass().getName());
    long initialErrorCount = registry.meter(METRIC_NAME_PREFIX + ".error").getCount();
    logger.error("an error message");
    assertThat(registry.meter(METRIC_NAME_PREFIX + ".all").getCount()).isEqualTo(initialErrorCount + 1);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 2 with Logger

use of org.apache.logging.log4j.core.Logger in project torodb by torodb.

the class Log4jUtils method setLogPackages.

public static void setLogPackages(Map<String, LogLevel> logPackages) {
    for (Map.Entry<String, LogLevel> logPackage : logPackages.entrySet()) {
        LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
        Logger logger = coreContext.getLogger(logPackage.getKey());
        setLevel(logger, logPackage.getValue());
    }
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Map(java.util.Map) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LogLevel(com.torodb.packaging.config.model.generic.LogLevel)

Example 3 with Logger

use of org.apache.logging.log4j.core.Logger in project HikariCP by brettwooldridge.

the class TestElf method setSlf4jTargetStream.

static void setSlf4jTargetStream(Class<?> clazz, PrintStream stream) {
    try {
        Log4jLogger log4Jlogger = (Log4jLogger) LoggerFactory.getLogger(clazz);
        Field field = clazz.getClassLoader().loadClass("org.apache.logging.slf4j.Log4jLogger").getDeclaredField("logger");
        field.setAccessible(true);
        Logger logger = (Logger) field.get(log4Jlogger);
        if (logger.getAppenders().containsKey("string")) {
            Appender appender = logger.getAppenders().get("string");
            logger.removeAppender(appender);
        }
        logger.addAppender(new StringAppender("string", stream));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) Appender(org.apache.logging.log4j.core.Appender) Field(java.lang.reflect.Field) Log4jLogger(org.apache.logging.slf4j.Log4jLogger) Logger(org.apache.logging.log4j.core.Logger) Log4jLogger(org.apache.logging.slf4j.Log4jLogger)

Example 4 with Logger

use of org.apache.logging.log4j.core.Logger in project geode by apache.

the class LogServiceIntegrationJUnitTest method removeAndRestoreConsoleAppenderShouldAffectRootLogger.

@Test
public void removeAndRestoreConsoleAppenderShouldAffectRootLogger() {
    LogService.reconfigure();
    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
    final Logger rootLogger = (Logger) LogService.getRootLogger();
    // assert "Console" is present for ROOT
    Appender appender = rootLogger.getAppenders().get(LogService.STDOUT);
    assertThat(appender).isNotNull();
    LogService.removeConsoleAppender();
    // assert "Console" is not present for ROOT
    appender = rootLogger.getAppenders().get(LogService.STDOUT);
    assertThat(appender).isNull();
    LogService.restoreConsoleAppender();
    // assert "Console" is present for ROOT
    appender = rootLogger.getAppenders().get(LogService.STDOUT);
    assertThat(appender).isNotNull();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) StatusLogger(org.apache.logging.log4j.status.StatusLogger) Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with Logger

use of org.apache.logging.log4j.core.Logger in project geode by apache.

the class LogServiceIntegrationJUnitTest method defaultConfigShouldIncludeStdout.

@Test
public void defaultConfigShouldIncludeStdout() {
    LogService.reconfigure();
    final Logger rootLogger = (Logger) LogService.getRootLogger();
    assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
    assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNotNull();
}
Also used : StatusLogger(org.apache.logging.log4j.status.StatusLogger) Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Logger (org.apache.logging.log4j.core.Logger)34 Test (org.junit.Test)20 LoggerContext (org.apache.logging.log4j.core.LoggerContext)6 Appender (org.apache.logging.log4j.core.Appender)5 StatusLogger (org.apache.logging.log4j.status.StatusLogger)5 Field (java.lang.reflect.Field)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 Marker (org.apache.logging.log4j.Marker)4 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)4 IgniteLogger (org.apache.ignite.IgniteLogger)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 List (java.util.List)2 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)2 RollingFileAppender (org.apache.logging.log4j.core.appender.RollingFileAppender)2 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)2 Log4jLogger (org.apache.logging.slf4j.Log4jLogger)2 LogLevel (com.torodb.packaging.config.model.generic.LogLevel)1