Search in sources :

Example 1 with LoggerConfig

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

the class TestHive method testMetaStoreApiTiming.

/**
   * Test logging of timing for metastore api calls
   *
   * @throws Throwable
   */
public void testMetaStoreApiTiming() throws Throwable {
    // Get the RootLogger which, if you don't have log4j2-test.properties defined, will only log ERRORs
    Logger logger = LogManager.getLogger("hive.ql.metadata.Hive");
    Level oldLevel = logger.getLevel();
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(logger.getName());
    loggerConfig.setLevel(Level.DEBUG);
    ctx.updateLoggers();
    // Create a String Appender to capture log output
    StringAppender appender = StringAppender.createStringAppender("%m");
    appender.addToLogger(logger.getName(), Level.DEBUG);
    appender.start();
    try {
        hm.clearMetaCallTiming();
        hm.getAllDatabases();
        hm.dumpAndClearMetaCallTiming("test");
        String logStr = appender.getOutput();
        String expectedString = "getAllDatabases_()=";
        Assert.assertTrue(logStr + " should contain <" + expectedString, logStr.contains(expectedString));
        // reset the log buffer, verify new dump without any api call does not contain func
        appender.reset();
        hm.dumpAndClearMetaCallTiming("test");
        logStr = appender.getOutput();
        Assert.assertFalse(logStr + " should not contain <" + expectedString, logStr.contains(expectedString));
    } finally {
        loggerConfig.setLevel(oldLevel);
        ctx.updateLoggers();
        appender.removeFromLogger(logger.getName());
    }
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) Level(org.apache.logging.log4j.Level) Logger(org.apache.logging.log4j.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 2 with LoggerConfig

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

the class TestLog4j2Appenders method setup.

@Before
public void setup() {
    // programmatically set root logger level to INFO. By default if log4j2-test.properties is not
    // available root logger will use ERROR log level
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    Configuration config = ctx.getConfiguration();
    LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
    loggerConfig.setLevel(Level.INFO);
    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) Before(org.junit.Before)

Example 3 with LoggerConfig

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

the class StringAppender method addToLogger.

@VisibleForTesting
public void addToLogger(String loggerName, Level level) {
    LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
    loggerConfig.addAppender(this, level, null);
    context.updateLoggers();
}
Also used : LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with LoggerConfig

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

the class LogConfigManager method setLoggerLevel.

public void setLoggerLevel(LoggerContext logContext, String loggerName, String newLevelStr) {
    Level newLevel = Level.getLevel(newLevelStr);
    Configuration configuration = logContext.getConfiguration();
    LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
    if (loggerConfig.getName().equalsIgnoreCase(loggerName)) {
        LOG.info("Setting {} log level to: {}", loggerConfig, newLevel);
        loggerConfig.setLevel(newLevel);
    } else {
        // create a new config. Make it additive (true) s.t. inherit parents appenders
        LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, newLevel, true);
        LOG.info("Adding config for: {} with level: {}", newLoggerConfig, newLevel);
        configuration.addLogger(loggerName, newLoggerConfig);
    }
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) LogLevel(org.apache.storm.generated.LogLevel) Level(org.apache.logging.log4j.Level) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 5 with LoggerConfig

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

the class HiveEventCounter method addToLogger.

@VisibleForTesting
public void addToLogger(String loggerName, Level level) {
    LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
    loggerConfig.addAppender(this, level, null);
    context.updateLoggers();
}
Also used : LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

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