Search in sources :

Example 41 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project camel by apache.

the class ConsumingAppender method newAppender.

public static Appender newAppender(String loggerName, String appenderName, String patter, Level level, Consumer<LogEvent> consumer) {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    config.removeLogger(loggerName);
    ConsumingAppender appender = new ConsumingAppender(appenderName, patter, consumer);
    appender.start();
    LoggerConfig loggerConfig = LoggerConfig.createLogger(true, level, loggerName, "true", new AppenderRef[] { AppenderRef.createAppenderRef(appenderName, null, null) }, null, config, null);
    loggerConfig.addAppender(appender, null, null);
    config.addLogger(loggerName, loggerConfig);
    ctx.updateLoggers();
    return appender;
}
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 42 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project spring-boot by spring-projects.

the class Log4J2LoggingSystem method setLogLevel.

@Override
public void setLogLevel(String loggerName, LogLevel logLevel) {
    Level level = LEVELS.convertSystemToNative(logLevel);
    LoggerConfig loggerConfig = getLoggerConfig(loggerName);
    if (loggerConfig == null) {
        loggerConfig = new LoggerConfig(loggerName, level, true);
        getLoggerContext().getConfiguration().addLogger(loggerName, loggerConfig);
    } else {
        loggerConfig.setLevel(level);
    }
    getLoggerContext().updateLoggers();
}
Also used : Level(org.apache.logging.log4j.Level) LogLevel(org.springframework.boot.logging.LogLevel) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 43 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig 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 44 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project opennms by OpenNMS.

the class Log4j2StringAppender method addToLogger.

public void addToLogger(String loggerName, Level level) {
    LoggerConfig loggerConfig = LOGGER_CONTEXT_CONFIGURATION.getLoggerConfig(loggerName);
    // Make sure the logger accepts messages at the given level
    if (level.isLessSpecificThan(loggerConfig.getLevel())) {
        loggerConfig.setLevel(level);
    }
    loggerConfig.addAppender(this, level, null);
    LOGGER_CONTEXT.updateLoggers();
}
Also used : LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 45 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project oxCore by GluuFederation.

the class LoggingHelper method configureConsoleAppender.

public static void configureConsoleAppender() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
    ConsoleAppender appender = ConsoleAppender.createDefaultAppenderForLayout(PatternLayout.createDefaultLayout());
    appender.start();
    config.addAppender(appender);
    AppenderRef[] refs = new AppenderRef[] { AppenderRef.createAppenderRef(appender.getName(), null, null) };
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.ALL, LogManager.ROOT_LOGGER_NAME, "true", refs, null, config, null);
    loggerConfig.addAppender(appender, null, null);
    config.addLogger(LogManager.ROOT_LOGGER_NAME, loggerConfig);
    ctx.updateLoggers();
}
Also used : AbstractConfiguration(org.apache.logging.log4j.core.config.AbstractConfiguration) ConsoleAppender(org.apache.logging.log4j.core.appender.ConsoleAppender) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)63 Configuration (org.apache.logging.log4j.core.config.Configuration)38 LoggerContext (org.apache.logging.log4j.core.LoggerContext)32 Appender (org.apache.logging.log4j.core.Appender)11 Level (org.apache.logging.log4j.Level)9 Test (org.junit.Test)7 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)6 Logger (org.apache.logging.log4j.Logger)5 Filter (org.apache.logging.log4j.core.Filter)5 Configuration.getConfiguration (javax.security.auth.login.Configuration.getConfiguration)4 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 ThresholdFilter (org.apache.logging.log4j.core.filter.ThresholdFilter)4 ConsoleAppender (org.apache.logging.log4j.core.appender.ConsoleAppender)3 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)3 PropertyChangeListener (java.beans.PropertyChangeListener)2 File (java.io.File)2 Path (java.nio.file.Path)2 Map (java.util.Map)2 AppenderContext (org.apache.geode.internal.logging.log4j.AppenderContext)2