use of ch.qos.logback.core.ConsoleAppender in project dropwizard by dropwizard.
the class AppenderFactoryCustomTimeZoneTest method testBuildAppenderWithTimeZonePlaceholderInLogFormat.
@Test
void testBuildAppenderWithTimeZonePlaceholderInLogFormat() throws Exception {
Appender appender = factory.build(configurationSourceProvider, "yaml/appender_with_time_zone_placeholder.yml").build(new LoggerContext(), "test-custom-time-zone", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
assertThat(appender).isInstanceOfSatisfying(AsyncAppender.class, asyncAppender -> assertThat(asyncAppender.getAppender("console-appender")).isInstanceOfSatisfying(ConsoleAppender.class, consoleAppender -> assertThat(consoleAppender.getEncoder()).isInstanceOfSatisfying(LayoutWrappingEncoder.class, encoder -> assertThat(encoder.getLayout()).isInstanceOfSatisfying(PatternLayoutBase.class, layout -> assertThat(layout.getPattern()).isEqualTo("custom format with UTC")))));
}
use of ch.qos.logback.core.ConsoleAppender in project dropwizard by dropwizard.
the class BootstrapLogging method bootstrap.
public static void bootstrap(Level level, DiscoverableLayoutFactory<ILoggingEvent> layoutFactory) {
LoggingUtil.hijackJDKLogging();
BOOTSTRAPPING_LOCK.lock();
try {
if (bootstrapped) {
return;
}
final Logger root = LoggingUtil.getLoggerContext().getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.detachAndStopAllAppenders();
final Layout<ILoggingEvent> layout = layoutFactory.build(root.getLoggerContext(), TimeZone.getDefault());
layout.start();
final ThresholdFilter filter = new ThresholdFilter();
filter.setLevel(level.toString());
filter.start();
final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.addFilter(filter);
appender.setContext(root.getLoggerContext());
final LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
layoutEncoder.setLayout(layout);
appender.setEncoder(layoutEncoder);
appender.start();
root.addAppender(appender);
bootstrapped = true;
} finally {
BOOTSTRAPPING_LOCK.unlock();
}
}
use of ch.qos.logback.core.ConsoleAppender in project dropwizard by dropwizard.
the class DefaultLoggingFactory method reset.
@Override
public void reset() {
CHANGE_LOGGER_CONTEXT_LOCK.lock();
try {
// Flush all the loggers and reinstate only the console logger as a
// sane default.
loggerContext.stop();
final Logger logger = loggerContext.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logger.detachAndStopAllAppenders();
final DropwizardLayout formatter = new DropwizardLayout(loggerContext, TimeZone.getDefault());
formatter.start();
final LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
layoutEncoder.setLayout(formatter);
final ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.addFilter(new ThresholdLevelFilterFactory().build(Level.INFO));
consoleAppender.setEncoder(layoutEncoder);
consoleAppender.setContext(loggerContext);
consoleAppender.start();
logger.addAppender(consoleAppender);
loggerContext.start();
} finally {
CHANGE_LOGGER_CONTEXT_LOCK.unlock();
}
}
use of ch.qos.logback.core.ConsoleAppender in project dropwizard by dropwizard.
the class DefaultLoggingFactoryTest method testResetAppenders.
@Test
void testResetAppenders() throws Exception {
final DefaultLoggingFactory config = factory.build(configurationSourceProvider, "yaml/logging.yml");
config.configure(new MetricRegistry(), "test-logger");
config.reset();
// There should be exactly one appender configured, a ConsoleAppender
assertThat(LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).isInstanceOfSatisfying(Logger.class, logger -> assertThat(logger.iteratorForAppenders()).toIterable().singleElement().isInstanceOf(ConsoleAppender.class).as("context").matches((Appender<?> a) -> a.getContext() != null).as("started").matches(LifeCycle::isStarted));
}
use of ch.qos.logback.core.ConsoleAppender in project midpoint by Evolveum.
the class Log method init.
private void init() {
opts = NinjaUtils.getOptions(context.getJc(), BaseOptions.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
if (opts.isVerbose()) {
ple.setPattern("%date [%thread] %-5level \\(%logger{46}\\): %message%n<");
} else {
ple.setPattern("%msg%n");
}
ple.setContext(lc);
ple.start();
ConsoleAppender out = setupAppender("STDOUT", "System.out", lc, setupEncoder(lc));
ConsoleAppender err = setupAppender("STDERR", "System.err", lc, setupEncoder(lc));
Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
if (LogTarget.SYSTEM_OUT.equals(target)) {
root.addAppender(out);
} else {
root.addAppender(err);
}
root.setLevel(Level.OFF);
info = setupLogger(LOGGER_SYS_OUT, opts);
error = setupLogger(LOGGER_SYS_ERR, opts);
error.setAdditive(false);
error.addAppender(err);
}
Aggregations