use of org.apache.logging.log4j.core.Logger in project metrics by dropwizard.
the class InstrumentedAppenderConfigTest method canRecordError.
@Test
public void canRecordError() throws Exception {
Logger logger = context.getLogger(this.getClass().getName());
long initialErrorCount = registry.meter(METRIC_NAME_PREFIX + ".error").getCount();
logger.error("an error message");
assertThat(registry.meter(METRIC_NAME_PREFIX + ".all").getCount()).isEqualTo(initialErrorCount + 1);
}
use of org.apache.logging.log4j.core.Logger in project torodb by torodb.
the class Log4jUtils method setLogPackages.
public static void setLogPackages(Map<String, LogLevel> logPackages) {
for (Map.Entry<String, LogLevel> logPackage : logPackages.entrySet()) {
LoggerContext coreContext = (LoggerContext) LogManager.getContext(false);
Logger logger = coreContext.getLogger(logPackage.getKey());
setLevel(logger, logPackage.getValue());
}
}
use of org.apache.logging.log4j.core.Logger in project HikariCP by brettwooldridge.
the class TestElf method setSlf4jTargetStream.
static void setSlf4jTargetStream(Class<?> clazz, PrintStream stream) {
try {
Log4jLogger log4Jlogger = (Log4jLogger) LoggerFactory.getLogger(clazz);
Field field = clazz.getClassLoader().loadClass("org.apache.logging.slf4j.Log4jLogger").getDeclaredField("logger");
field.setAccessible(true);
Logger logger = (Logger) field.get(log4Jlogger);
if (logger.getAppenders().containsKey("string")) {
Appender appender = logger.getAppenders().get("string");
logger.removeAppender(appender);
}
logger.addAppender(new StringAppender("string", stream));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.logging.log4j.core.Logger in project geode by apache.
the class LogServiceIntegrationJUnitTest method removeAndRestoreConsoleAppenderShouldAffectRootLogger.
@Test
public void removeAndRestoreConsoleAppenderShouldAffectRootLogger() {
LogService.reconfigure();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
final Logger rootLogger = (Logger) LogService.getRootLogger();
// assert "Console" is present for ROOT
Appender appender = rootLogger.getAppenders().get(LogService.STDOUT);
assertThat(appender).isNotNull();
LogService.removeConsoleAppender();
// assert "Console" is not present for ROOT
appender = rootLogger.getAppenders().get(LogService.STDOUT);
assertThat(appender).isNull();
LogService.restoreConsoleAppender();
// assert "Console" is present for ROOT
appender = rootLogger.getAppenders().get(LogService.STDOUT);
assertThat(appender).isNotNull();
}
use of org.apache.logging.log4j.core.Logger in project geode by apache.
the class LogServiceIntegrationJUnitTest method defaultConfigShouldIncludeStdout.
@Test
public void defaultConfigShouldIncludeStdout() {
LogService.reconfigure();
final Logger rootLogger = (Logger) LogService.getRootLogger();
assertThat(LogService.isUsingGemFireDefaultConfig()).as(LogService.getConfigInformation()).isTrue();
assertThat(rootLogger.getAppenders().get(LogService.STDOUT)).isNotNull();
}
Aggregations