Search in sources :

Example 81 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project elasticsearch by elastic.

the class EvilLoggerConfigurationTests method tearDown.

@Override
public void tearDown() throws Exception {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configurator.shutdown(context);
    super.tearDown();
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 82 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project cryptomator by cryptomator.

the class DebugMode method enable.

private void enable() {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    LOGGER_UPGRADES.forEach(loggerUpgrade -> loggerUpgrade.execute(config));
    context.updateLoggers();
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 83 with LoggerContext

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

the class Log4jUtils method setRootLevel.

public static void setRootLevel(LogLevel logLevel) {
    LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
    Configuration configuration = coreContext.getConfiguration();
    for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
        setLevel(loggerConfig, logLevel);
    }
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 84 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project graylog2-server by Graylog2.

the class CmdLineTool method initializeLogging.

private void initializeLogging(final Level logLevel) {
    final LoggerContext context = (LoggerContext) LogManager.getContext(false);
    final org.apache.logging.log4j.core.config.Configuration config = context.getConfiguration();
    config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).setLevel(logLevel);
    config.getLoggerConfig(Main.class.getPackage().getName()).setLevel(logLevel);
    context.updateLoggers(config);
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 85 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project graylog2-server by Graylog2.

the class LoggersResource method getLoggerConfigs.

@VisibleForTesting
protected Collection<LoggerConfig> getLoggerConfigs() {
    final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    final Configuration configuration = loggerContext.getConfiguration();
    return configuration.getLoggers().values();
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

LoggerContext (org.apache.logging.log4j.core.LoggerContext)163 Configuration (org.apache.logging.log4j.core.config.Configuration)57 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)36 Test (org.junit.Test)33 Appender (org.apache.logging.log4j.core.Appender)18 File (java.io.File)12 IOException (java.io.IOException)12 Logger (org.apache.logging.log4j.Logger)11 BeforeClass (org.junit.BeforeClass)11 Map (java.util.Map)10 Level (org.apache.logging.log4j.Level)8 LogEvent (org.apache.logging.log4j.core.LogEvent)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)7 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)7 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)7 Logger (org.apache.logging.log4j.core.Logger)6 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)5 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)4 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4