Search in sources :

Example 91 with LoggerContext

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

the class Log4J2Logger method setLevel.

/**
     * Sets level for internal log4j implementation.
     *
     * @param level Log level to set.
     */
public void setLevel(Level level) {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration conf = ctx.getConfiguration();
    conf.getLoggerConfig(impl.getName()).setLevel(level);
    ctx.updateLoggers(conf);
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 92 with LoggerContext

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

the class GfshInitFileJUnitTest method tearDownAfterClass.

/*
   * Restore logging to state prior to the execution of this class
   */
@AfterClass
public static void tearDownAfterClass() throws Exception {
    for (Handler handler : saveHandlers) {
        julLogger.addHandler(handler);
    }
    if (saveLog4j2Config == null) {
        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    } else {
        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, saveLog4j2Config);
        ((LoggerContext) LogManager.getContext(false)).reconfigure();
    }
}
Also used : Handler(java.util.logging.Handler) LoggerContext(org.apache.logging.log4j.core.LoggerContext) AfterClass(org.junit.AfterClass)

Example 93 with LoggerContext

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

the class DUnitLauncher method addSuspectFileAppender.

/**
   * Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used
   * later to scan for suspect strings. The pattern of the messages conforms to the original log
   * format so that hydra will be able to parse them.
   */
private static void addSuspectFileAppender(final String workspaceDir) {
    final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath();
    final LoggerContext appenderContext = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogService.BASE_LOGGER_NAME)).getContext();
    final PatternLayout layout = PatternLayout.createLayout("[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n", null, null, null, Charset.defaultCharset(), true, false, "", "");
    final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false", DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null, appenderContext.getConfiguration());
    fileAppender.start();
    LoggerConfig loggerConfig = appenderContext.getConfiguration().getLoggerConfig(LogService.BASE_LOGGER_NAME);
    loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
Also used : FileAppender(org.apache.logging.log4j.core.appender.FileAppender) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) File(java.io.File) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 94 with LoggerContext

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

the class DistributedSystemLogFileJUnitTest method tearDown.

@After
public void tearDown() throws Exception {
    if (this.system != null) {
        this.system.disconnect();
        this.system = null;
    }
    // We will want to remove this at some point but right now the log context
    // does not clear out the security logconfig between tests
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    context.stop();
}
Also used : LoggerContext(org.apache.logging.log4j.core.LoggerContext) After(org.junit.After)

Example 95 with LoggerContext

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

the class JabRefLogger method setLogLevelToDebugForJabRefClasses.

private static void setLogLevelToDebugForJabRefClasses() {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig("org.jabref");
    loggerConfig.setLevel(Level.DEBUG);
    ctx.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)

Aggregations

LoggerContext (org.apache.logging.log4j.core.LoggerContext)163 Configuration (org.apache.logging.log4j.core.config.Configuration)57 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)36 Test (org.junit.Test)33 Appender (org.apache.logging.log4j.core.Appender)18 File (java.io.File)12 IOException (java.io.IOException)12 Logger (org.apache.logging.log4j.Logger)11 BeforeClass (org.junit.BeforeClass)11 Map (java.util.Map)10 Level (org.apache.logging.log4j.Level)8 LogEvent (org.apache.logging.log4j.core.LogEvent)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)7 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)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 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 RoutingAppender (org.apache.logging.log4j.core.appender.routing.RoutingAppender)4 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4