use of org.apache.logging.log4j.core.LoggerContext in project camel by apache.
the class LogVerifier method newAppender.
private Appender newAppender() {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
LogAppender appender = new LogAppender("cdi-rule");
appender.start();
config.addAppender(appender);
config.getRootLogger().removeAppender("cdi-rule");
config.getRootLogger().addAppender(appender, Level.TRACE, null);
ctx.updateLoggers();
return appender;
}
use of org.apache.logging.log4j.core.LoggerContext in project camel by apache.
the class LogBodyWithNewLineTest method setUp.
public void setUp() throws Exception {
super.setUp();
writer = new StringWriter();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Appender appender = WriterAppender.newBuilder().setLayout(PatternLayout.newBuilder().withPattern(PatternLayout.SIMPLE_CONVERSION_PATTERN).build()).setTarget(writer).setName("Writer").build();
appender.start();
config.addAppender(appender);
config.getRootLogger().removeAppender("Writer");
config.getRootLogger().addAppender(appender, Level.INFO, null);
ctx.updateLoggers();
}
use of org.apache.logging.log4j.core.LoggerContext 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.LoggerContext 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.LoggerContext in project storm by apache.
the class LogConfigManager method resetLogLevels.
// function called on timer to reset log levels last set to DEBUG
// also called from processLogConfigChange
public void resetLogLevels() {
TreeMap<String, LogLevel> latestLogLevelMap = latestLogConfig.get();
LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
for (String loggerName : latestLogLevelMap.descendingKeySet()) {
LogLevel loggerSetting = latestLogLevelMap.get(loggerName);
long timeout = loggerSetting.get_reset_log_level_timeout_epoch();
String resetLogLevel = loggerSetting.get_reset_log_level();
if (timeout < Time.currentTimeMillis()) {
LOG.info("{}: Resetting level to {}", loggerName, resetLogLevel);
setLoggerLevel(loggerContext, loggerName, resetLogLevel);
}
latestLogConfig.getAndUpdate(input -> {
TreeMap<String, LogLevel> result = new TreeMap<>(input);
result.remove(loggerName);
return result;
});
}
loggerContext.updateLoggers();
}
Aggregations