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());
}
}
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();
}
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();
}
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);
}
}
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();
}
Aggregations