Search in sources :

Example 11 with Level

use of org.apache.logging.log4j.Level in project torodb by torodb.

the class Log4jUtils method setLevel.

private static void setLevel(LoggerConfig loggerConfig, LogLevel logLevel) {
    Level log4jLevel = Log4jLevelToLogLevelMapper.map(logLevel);
    loggerConfig.setLevel(log4jLevel);
}
Also used : Level(org.apache.logging.log4j.Level) LogLevel(com.torodb.packaging.config.model.generic.LogLevel)

Example 12 with Level

use of org.apache.logging.log4j.Level in project torodb by torodb.

the class Log4jUtils method setLevel.

private static void setLevel(Logger logger, LogLevel logLevel) {
    Level log4jLevel = Log4jLevelToLogLevelMapper.map(logLevel);
    logger.setLevel(log4jLevel);
}
Also used : Level(org.apache.logging.log4j.Level) LogLevel(com.torodb.packaging.config.model.generic.LogLevel)

Example 13 with Level

use of org.apache.logging.log4j.Level in project hutool by looly.

the class Log4j2Log method log.

@Override
public void log(String fqcn, cn.hutool.log.level.Level level, Throwable t, String format, Object... arguments) {
    Level log4j2Level;
    switch(level) {
        case TRACE:
            log4j2Level = Level.TRACE;
            break;
        case DEBUG:
            log4j2Level = Level.DEBUG;
            break;
        case INFO:
            log4j2Level = Level.INFO;
            break;
        case WARN:
            log4j2Level = Level.WARN;
            break;
        case ERROR:
            log4j2Level = Level.ERROR;
            break;
        default:
            throw new Error(StrUtil.format("Can not identify level: {}", level));
    }
    logIfEnabled(fqcn, log4j2Level, t, format, arguments);
}
Also used : Level(org.apache.logging.log4j.Level)

Example 14 with Level

use of org.apache.logging.log4j.Level in project oxTrust by GluuFederation.

the class AppInitializer method updateLoggingSeverity.

public void updateLoggingSeverity(@Observes @ConfigurationUpdate AppConfiguration appConfiguration) {
    String loggingLevel = appConfiguration.getLoggingLevel();
    if (StringHelper.isEmpty(loggingLevel)) {
        return;
    }
    log.info("Setting loggers level to: '{}'", loggingLevel);
    LoggerContext loggerContext = LoggerContext.getContext(false);
    if (StringHelper.equalsIgnoreCase("DEFAULT", loggingLevel)) {
        log.info("Reloadming log4j configuration");
        loggerContext.reconfigure();
        return;
    }
    Level level = Level.toLevel(loggingLevel, Level.INFO);
    for (org.apache.logging.log4j.core.Logger logger : loggerContext.getLoggers()) {
        String loggerName = logger.getName();
        if (loggerName.startsWith("org.xdi.service") || loggerName.startsWith("org.xdi.oxauth") || loggerName.startsWith("org.gluu")) {
            logger.setLevel(level);
        }
    }
}
Also used : Level(org.apache.logging.log4j.Level) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 15 with Level

use of org.apache.logging.log4j.Level in project gatk by broadinstitute.

the class UtilsUnitTest method testSetLoggingLevel.

/**
     * Test setting the global logging level for Picard, Log4j, MinLog and java.util.logging.
     *
     * Note that there are three very similar, but not identical, logging level enums from different namespaces
     * being used here. The one used by Picard (and Hellbender --verbosity) of type "Log.LogLevel", the parallel
     * one used by log4j of type "Level", and the one used by java.utils.logging.
     *
     */
@Test
public void testSetLoggingLevel() {
    // Query and cache the initial  Log4j level in place at the start of the tests so we can restore it at the
    // end of the tests. Also, since we're QUERYING the Log4j level, but we're SETTING the level using the
    // LoggingUtils API, we also need to verify here that the initial level is one of the narrower set of levels
    // that is supported by LoggingUtils, since those are the only ones we can restore through the LoggingUtils API.
    Level initialLevel = logger.getLevel();
    boolean goodInitialLevel = initialLevel == Level.DEBUG || initialLevel == Level.WARN || initialLevel == Level.ERROR || initialLevel == Level.INFO;
    Assert.assertTrue(goodInitialLevel);
    // Set and test each supported logging level in turn
    LoggingUtils.setLoggingLevel(LogLevel.DEBUG);
    Assert.assertTrue(logger.getLevel() == Level.DEBUG);
    LoggingUtils.setLoggingLevel(LogLevel.WARNING);
    Assert.assertTrue(logger.getLevel() == Level.WARN);
    LoggingUtils.setLoggingLevel(LogLevel.ERROR);
    Assert.assertTrue(logger.getLevel() == Level.ERROR);
    LoggingUtils.setLoggingLevel(LogLevel.INFO);
    Assert.assertTrue(logger.getLevel() == Level.INFO);
    // Restore the logging level back to the original level in place at the beginning of the test
    LoggingUtils.setLoggingLevel(LoggingUtils.levelFromLog4jLevel(initialLevel));
    Assert.assertTrue(logger.getLevel() == initialLevel);
}
Also used : LogLevel(htsjdk.samtools.util.Log.LogLevel) Level(org.apache.logging.log4j.Level) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

Level (org.apache.logging.log4j.Level)152 Test (org.junit.Test)31 LoggerContext (org.apache.logging.log4j.core.LoggerContext)27 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)27 Logger (org.apache.logging.log4j.Logger)25 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)25 Message (org.apache.logging.log4j.message.Message)23 Marker (org.apache.logging.log4j.Marker)21 Configuration (org.apache.logging.log4j.core.config.Configuration)21 Map (java.util.Map)16 HashMap (java.util.HashMap)14 LogEvent (org.apache.logging.log4j.core.LogEvent)13 Test (org.junit.jupiter.api.Test)12 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)11 StringMap (org.apache.logging.log4j.util.StringMap)10 Appender (org.apache.logging.log4j.core.Appender)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)8