use of org.apache.logging.log4j.core.config.LoggerConfig in project graylog2-server by Graylog2.
the class LoggersResource method getLoggerLevel.
@VisibleForTesting
protected Level getLoggerLevel(final String loggerName) {
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
return loggerConfig.getLevel();
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project graylog2-server by Graylog2.
the class LoggersResource method loggers.
@GET
@Timed
@ApiOperation(value = "List all loggers and their current levels")
@Produces(MediaType.APPLICATION_JSON)
public LoggersSummary loggers() {
final Collection<LoggerConfig> loggerConfigs = getLoggerConfigs();
final Map<String, SingleLoggerSummary> loggers = Maps.newHashMapWithExpectedSize(loggerConfigs.size());
for (LoggerConfig config : loggerConfigs) {
if (!isPermitted(RestPermissions.LOGGERS_READ, config.getName())) {
continue;
}
final Level level = config.getLevel();
loggers.put(config.getName(), SingleLoggerSummary.create(level.toString().toLowerCase(Locale.ENGLISH), level.intLevel()));
}
return LoggersSummary.create(loggers);
}
use of org.apache.logging.log4j.core.config.LoggerConfig 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.config.LoggerConfig in project geode by apache.
the class AlertAppender method addAlertListener.
public synchronized void addAlertListener(final DistributedMember member, final int alertLevel) {
final Level level = LogService.toLevel(alertLevelToLogLevel(alertLevel));
if (this.listeners.size() == 0) {
this.appenderContext.getLoggerContext().addPropertyChangeListener(this);
}
addListenerToSortedList(new Listener(level, member));
LoggerConfig loggerConfig = this.appenderContext.getLoggerConfig();
loggerConfig.addAppender(this, this.listeners.get(0).getLevel(), null);
if (logger.isDebugEnabled()) {
logger.debug("Added/Replaced alert listener for member {} at level {}", member, level);
}
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project geode by apache.
the class LogService method removeConsoleAppender.
/**
* Removes STDOUT ConsoleAppender from ROOT logger. Only called when using the log4j2-default.xml
* configuration. This is done when creating the LogWriterAppender for log-file. The Appender
* instance is stored in stdoutAppender so it can be restored later using restoreConsoleAppender.
*/
public static synchronized void removeConsoleAppender() {
final AppenderContext appenderContext = LogService.getAppenderContext(LogService.ROOT_LOGGER_NAME);
final LoggerConfig config = appenderContext.getLoggerConfig();
Appender stdout = config.getAppenders().get(STDOUT);
if (stdout != null) {
config.removeAppender(STDOUT);
stdoutAppender = stdout;
appenderContext.getLoggerContext().updateLoggers();
}
}
Aggregations