Search in sources :

Example 11 with LoggerConfig

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();
}
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) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 12 with LoggerConfig

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);
}
Also used : SingleLoggerSummary(org.graylog2.rest.models.system.loggers.responses.SingleLoggerSummary) Level(org.apache.logging.log4j.Level) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 13 with LoggerConfig

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();
}
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) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with LoggerConfig

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);
    }
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) Level(org.apache.logging.log4j.Level) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 15 with LoggerConfig

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();
    }
}
Also used : Appender(org.apache.logging.log4j.core.Appender) AppenderContext(org.apache.geode.internal.logging.log4j.AppenderContext) 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