use of org.apache.logging.slf4j.Log4jLogger 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.slf4j.Log4jLogger in project HikariCP by brettwooldridge.
the class TestElf method setSlf4jLogLevel.
static void setSlf4jLogLevel(Class<?> clazz, Level logLevel) {
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);
logger.setLevel(logLevel);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations