Search in sources :

Example 11 with LoggerContext

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

the class Log4J2LoggingSystem method cleanUp.

@Override
public void cleanUp() {
    super.cleanUp();
    LoggerContext loggerContext = getLoggerContext();
    markAsUninitialized(loggerContext);
    loggerContext.getConfiguration().removeFilter(FILTER);
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 12 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project torodb by torodb.

the class Log4jUtils method reconfigure.

public static void reconfigure(String configurationFile) {
    try {
        LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
        coreContext.setConfigLocation(new File(configurationFile).toURI());
    } catch (Exception ex) {
        throw new SystemException(ex);
    }
}
Also used : SystemException(com.torodb.core.exceptions.SystemException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) File(java.io.File) SystemException(com.torodb.core.exceptions.SystemException)

Example 13 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project torodb by torodb.

the class Log4jUtils method appendToLogFile.

public static void appendToLogFile(String logFile) {
    LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
    Configuration configuration = coreContext.getConfiguration();
    final Layout<? extends Serializable> layout = PatternLayout.newBuilder().withConfiguration(configuration).withPattern("%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n").build();
    final Appender appender = FileAppender.createAppender(logFile, "false", "false", "File", "true", "false", null, null, layout, null, "false", null, configuration);
    appender.start();
    for (LoggerConfig loggerConfig : configuration.getLoggers().values()) {
        configuration.addLoggerAppender(coreContext.getLogger(loggerConfig.getName()), appender);
    }
}
Also used : AbstractAppender(org.apache.logging.log4j.core.appender.AbstractAppender) Appender(org.apache.logging.log4j.core.Appender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 14 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project torodb by torodb.

the class Log4jUtils method setLogPackages.

public static void setLogPackages(Map<String, LogLevel> logPackages) {
    for (Map.Entry<String, LogLevel> logPackage : logPackages.entrySet()) {
        LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
        Logger logger = coreContext.getLogger(logPackage.getKey());
        setLevel(logger, logPackage.getValue());
    }
}
Also used : Logger(org.apache.logging.log4j.core.Logger) Map(java.util.Map) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LogLevel(com.torodb.packaging.config.model.generic.LogLevel)

Example 15 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext 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)

Aggregations

LoggerContext (org.apache.logging.log4j.core.LoggerContext)156 Configuration (org.apache.logging.log4j.core.config.Configuration)53 Test (org.junit.Test)33 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)32 Appender (org.apache.logging.log4j.core.Appender)15 File (java.io.File)12 IOException (java.io.IOException)11 Logger (org.apache.logging.log4j.Logger)11 BeforeClass (org.junit.BeforeClass)11 Map (java.util.Map)9 Level (org.apache.logging.log4j.Level)8 LogEvent (org.apache.logging.log4j.core.LogEvent)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)7 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)7 Logger (org.apache.logging.log4j.core.Logger)6 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)5 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)5 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)5 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4