Search in sources :

Example 11 with Logger

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

the class CsvParameterLayoutAllAsyncTest method testLayoutDefaultNormal.

@Test
public void testLayoutDefaultNormal() throws Exception {
    final Logger root = (Logger) LogManager.getRootLogger();
    CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), false);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 12 with Logger

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

the class HttpServer method getLogDir.

String getLogDir(Configuration conf) {
    String logDir = conf.get("hive.log.dir");
    if (logDir == null) {
        logDir = System.getProperty("hive.log.dir");
    }
    if (logDir != null) {
        return logDir;
    }
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    for (Logger logger : context.getLoggers()) {
        for (Appender appender : logger.getAppenders().values()) {
            if (appender instanceof AbstractOutputStreamAppender) {
                OutputStreamManager manager = ((AbstractOutputStreamAppender<?>) appender).getManager();
                if (manager instanceof FileManager) {
                    String fileName = ((FileManager) manager).getFileName();
                    if (fileName != null) {
                        return fileName.substring(0, fileName.lastIndexOf('/'));
                    }
                }
            }
        }
    }
    return null;
}
Also used : AbstractOutputStreamAppender(org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender) Appender(org.apache.logging.log4j.core.Appender) OutputStreamManager(org.apache.logging.log4j.core.appender.OutputStreamManager) AbstractOutputStreamAppender(org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender) Logger(org.apache.logging.log4j.core.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) FileManager(org.apache.logging.log4j.core.appender.FileManager)

Example 13 with Logger

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

the class TestElf method setSlf4jLogLevel.

static void setSlf4jLogLevel(Class<?> clazz, Level logLevel) {
    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);
        logger.setLevel(logLevel);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : 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 14 with Logger

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

the class InstrumentedAppenderConfigTest method canRecordAll.

// The biggest test is that we can initialize the log4j2 config at all.
@Test
public void canRecordAll() throws Exception {
    Logger logger = context.getLogger(this.getClass().getName());
    long initialAllCount = registry.meter(METRIC_NAME_PREFIX + ".all").getCount();
    logger.error("an error message");
    assertThat(registry.meter(METRIC_NAME_PREFIX + ".all").getCount()).isEqualTo(initialAllCount + 1);
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Test(org.junit.Test)

Example 15 with Logger

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

the class InstrumentedAppenderConfigTest method noInvalidRecording.

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

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