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;
}
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();
}
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);
}
}
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();
}
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();
}
Aggregations