use of org.apache.logging.log4j.core.LoggerContext in project graylog2-server by Graylog2.
the class LoggersResource method setLoggerLevel.
@VisibleForTesting
protected void setLoggerLevel(final String loggerName, final Level level) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration config = context.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
if (loggerName.equals(loggerConfig.getName())) {
loggerConfig.setLevel(level);
} else {
final LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, level, loggerConfig.isAdditive());
newLoggerConfig.setLevel(level);
config.addLogger(loggerName, newLoggerConfig);
}
context.updateLoggers();
}
use of org.apache.logging.log4j.core.LoggerContext in project graylog2-server by Graylog2.
the class CmdLineTool method addInstrumentedAppender.
private void addInstrumentedAppender(final MetricRegistry metrics, final Level level) {
final InstrumentedAppender appender = new InstrumentedAppender(metrics, null, null, false);
appender.start();
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final org.apache.logging.log4j.core.config.Configuration config = context.getConfiguration();
config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, level, null);
context.updateLoggers(config);
}
use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.
the class Configurator method getLoggerConfig.
public static LoggerConfig getLoggerConfig(final String name) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
LoggerConfig logConfig = config.getLoggerConfig(name);
if (!logConfig.getName().equals(name)) {
throw new IllegalStateException("LoggerConfig does not exist for " + name);
}
return logConfig;
}
use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.
the class Configurator method setLevel.
public static void setLevel(String name, Level level) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
LoggerConfig logConfig = getLoggerConfig(name);
logConfig.setLevel(level);
context.updateLoggers();
if (level.isLessSpecificThan(Level.DEBUG)) {
LogService.configureFastLoggerDelegating();
}
}
use of org.apache.logging.log4j.core.LoggerContext in project ignite by apache.
the class Log4J2Logger method createConsoleLogger.
/**
* Creates console appender with some reasonable default logging settings.
*
* @return Logger with auto configured console appender.
*/
public static Logger createConsoleLogger() {
LoggerContext ctx = (LoggerContext) LogManager.getContext(true);
Configuration cfg = ctx.getConfiguration();
PatternLayout.Builder builder = PatternLayout.newBuilder();
builder.withPattern("%d{ABSOLUTE}][%-5p][%t][%c{1}] %m%n").withCharset(Charset.defaultCharset()).withAlwaysWriteExceptions(false).withNoConsoleNoAnsi(false);
PatternLayout layout = builder.build();
ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder();
consoleAppenderBuilder.withName(CONSOLE_APPENDER).withLayout(layout);
ConsoleAppender consoleApp = consoleAppenderBuilder.build();
consoleApp.start();
AppenderRef ref = AppenderRef.createAppenderRef(CONSOLE_APPENDER, Level.TRACE, null);
AppenderRef[] refs = { ref };
LoggerConfig logCfg = LoggerConfig.createLogger(false, Level.INFO, LogManager.ROOT_LOGGER_NAME, "", refs, null, null, null);
logCfg.addAppender(consoleApp, null, null);
cfg.addAppender(consoleApp);
cfg.addLogger(LogManager.ROOT_LOGGER_NAME, logCfg);
ctx.updateLoggers(cfg);
return (Logger) LogManager.getContext().getLogger(LogManager.ROOT_LOGGER_NAME);
}
Aggregations