Search in sources :

Example 26 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.

the class AsyncLoggerConfigTest method testIncludeLocationDefaultsToFalse.

@Test
public void testIncludeLocationDefaultsToFalse() {
    final LoggerConfig rootLoggerConfig = AsyncLoggerConfig.RootLogger.createLogger(null, "INFO", null, new AppenderRef[0], null, new DefaultConfiguration(), null);
    assertFalse("Include location should default to false for async logggers", rootLoggerConfig.isIncludeLocation());
    final LoggerConfig loggerConfig = AsyncLoggerConfig.createLogger(null, "INFO", "com.foo.Bar", null, new AppenderRef[0], null, new DefaultConfiguration(), null);
    assertFalse("Include location should default to false for async logggers", loggerConfig.isIncludeLocation());
}
Also used : DefaultConfiguration(org.apache.logging.log4j.core.config.DefaultConfiguration) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) Test(org.junit.Test)

Example 27 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project gatk by broadinstitute.

the class LoggingUtils method setLog4JLoggingLevel.

private static void setLog4JLoggingLevel(Log.LogLevel verbosity) {
    // Now establish the logging level used by log4j by propagating the requested
    // logging level to all loggers associated with our logging configuration.
    final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
    final Configuration loggerContextConfig = loggerContext.getConfiguration();
    final String contextClassName = LoggingUtils.class.getName();
    final LoggerConfig loggerConfig = loggerContextConfig.getLoggerConfig(contextClassName);
    loggerConfig.setLevel(levelToLog4jLevel(verbosity));
    loggerContext.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)

Example 28 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project Anserini by castorini.

the class TrainingDataGenerator method createNewLoggerConfig.

/**
   * Dynamically creates a logger configuration with an appender that writes to a file.
   * This logger is used to write training data.
   *
   * @param loggerName     the name of the logger to create
   * @param outputFilePath the file path to write logs to
   * @param patternLayout  layout for the logger, if null just display
   *                       the message using DEFAULT_CONVERSION_PATTERN
   */
private static void createNewLoggerConfig(String loggerName, String outputFilePath, String patternLayout) {
    // Ignore null output files
    if (outputFilePath == null)
        return;
    // Create a logger to write the training data
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    final Configuration config = ctx.getConfiguration();
    Layout layout = PatternLayout.createLayout(patternLayout == null ? PatternLayout.DEFAULT_CONVERSION_PATTERN : patternLayout, config, null, StandardCharsets.UTF_8, false, false, null, null);
    Appender appender = FileAppender.createAppender(outputFilePath, "false", "false", loggerName, "true", "false", "false", "2000", layout, null, "false", null, config);
    appender.start();
    config.addAppender(appender);
    // Adding reference to the appender
    AppenderRef ref = AppenderRef.createAppenderRef(loggerName, null, null);
    AppenderRef[] refs = new AppenderRef[] { ref };
    LoggerConfig loggerConfig = LoggerConfig.createLogger("false", Level.TRACE, loggerName, "true", refs, null, config, null);
    // Adding appender to logger, and adding logger to context
    loggerConfig.addAppender(appender, null, null);
    config.addLogger(loggerName, loggerConfig);
    ctx.updateLoggers();
}
Also used : Appender(org.apache.logging.log4j.core.Appender) FileAppender(org.apache.logging.log4j.core.appender.FileAppender) Configuration(org.apache.logging.log4j.core.config.Configuration) Layout(org.apache.logging.log4j.core.Layout) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 29 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project pyramid by cheng-li.

the class IMLLogisticRegressionTest method main.

public static void main(String[] args) throws Exception {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();
    test1();
}
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)

Example 30 with LoggerConfig

use of org.apache.logging.log4j.core.config.LoggerConfig in project pyramid by cheng-li.

the class LogisticRegressionTest method main.

public static void main(String[] args) throws Exception {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();
    //        test3();
    test5();
}
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

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