use of org.apache.logging.log4j.core.config.Configuration 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.Configuration in project curiostack by curioswitch.
the class MonitoringModule method configureLogMetrics.
private static void configureLogMetrics() {
InstrumentedAppender appender = InstrumentedAppender.createAppender("PROMETHEUS");
appender.start();
LoggerContext context = (LoggerContext) LogManager.getContext(false);
Configuration config = context.getConfiguration();
config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, null, null);
context.updateLoggers(config);
}
use of org.apache.logging.log4j.core.config.Configuration 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();
}
use of org.apache.logging.log4j.core.config.Configuration 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();
}
use of org.apache.logging.log4j.core.config.Configuration in project ignite by apache.
the class Log4J2Logger method createConsoleLogger.
/**
* Creates console appender with some reasonable default logging settings.
*
* @return Logger with auto configured console appender.
*/
public Logger createConsoleLogger() {
// from http://logging.apache.org/log4j/2.x/manual/customconfig.html
final LoggerContext ctx = impl.getContext();
final Configuration cfg = ctx.getConfiguration();
PatternLayout.Builder builder = PatternLayout.newBuilder().withPattern("%d{ISO8601}][%-5p][%t][%c{1}] %m%n").withCharset(Charset.defaultCharset()).withAlwaysWriteExceptions(false).withNoConsoleNoAnsi(false);
PatternLayout layout = builder.build();
ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder().withName(CONSOLE_APPENDER).withLayout(layout);
ConsoleAppender consoleApp = consoleAppenderBuilder.build();
consoleApp.start();
cfg.addAppender(consoleApp);
cfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null);
ctx.updateLoggers(cfg);
return ctx.getRootLogger();
}
Aggregations