Search in sources :

Example 6 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project dropwizard by dropwizard.

the class BootstrapLogging method bootstrap.

public static void bootstrap(Level level) {
    LoggingUtil.hijackJDKLogging();
    BOOTSTRAPPING_LOCK.lock();
    try {
        if (bootstrapped) {
            return;
        }
        final Logger root = LoggingUtil.getLoggerContext().getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
        root.detachAndStopAllAppenders();
        final DropwizardLayout formatter = new DropwizardLayout(root.getLoggerContext(), TimeZone.getDefault());
        formatter.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(formatter);
        appender.setEncoder(layoutEncoder);
        appender.start();
        root.addAppender(appender);
        bootstrapped = true;
    } finally {
        BOOTSTRAPPING_LOCK.unlock();
    }
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) ThresholdFilter(ch.qos.logback.classic.filter.ThresholdFilter) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LayoutWrappingEncoder(ch.qos.logback.core.encoder.LayoutWrappingEncoder)

Example 7 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project sonarqube by SonarSource.

the class AppLoggingTest method root_logger_only_writes_to_console_with_formatting_when_running_from_sonar_script.

@Test
public void root_logger_only_writes_to_console_with_formatting_when_running_from_sonar_script() {
    emulateRunFromSonarScript();
    LoggerContext ctx = underTest.configure();
    Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
    ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) rootLogger.getAppender("APP_CONSOLE");
    verifyAppFormattedLogEncoder(consoleAppender.getEncoder());
    assertThat(rootLogger.iteratorForAppenders()).hasSize(1);
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 8 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project sonarqube by SonarSource.

the class LogbackHelper method newConsoleAppender.

/**
   * Creates a new {@link ConsoleAppender} to {@code System.out} with the specified name and log pattern.
   *
   * @see #buildLogPattern(RootLoggerConfig)
   */
public ConsoleAppender<ILoggingEvent> newConsoleAppender(Context loggerContext, String name, String logPattern) {
    PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
    consoleEncoder.setContext(loggerContext);
    consoleEncoder.setPattern(logPattern);
    consoleEncoder.start();
    ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
    consoleAppender.setContext(loggerContext);
    consoleAppender.setEncoder(consoleEncoder);
    consoleAppender.setName(name);
    consoleAppender.setTarget("System.out");
    consoleAppender.start();
    return consoleAppender;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 9 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project sonarqube by SonarSource.

the class CeProcessLoggingTest method startup_logger_prints_to_only_to_system_out.

@Test
public void startup_logger_prints_to_only_to_system_out() {
    LoggerContext ctx = underTest.configure(props);
    Logger startup = ctx.getLogger("startup");
    assertThat(startup.isAdditive()).isFalse();
    Appender appender = startup.getAppender("CONSOLE");
    assertThat(appender).isInstanceOf(ConsoleAppender.class);
    ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
    assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
    assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
    PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
    assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 10 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project sling by apache.

the class LogConfigManager method getDefaultAppender.

public Appender<ILoggingEvent> getDefaultAppender() {
    OutputStreamAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setName(DEFAULT_CONSOLE_APPENDER_NAME);
    appender.setContext(loggerContext);
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern(LOG_PATTERN_DEFAULT);
    encoder.setContext(loggerContext);
    encoder.start();
    appender.setEncoder(encoder);
    appender.start();
    return appender;
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)10 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)10 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)7 LoggerContext (ch.qos.logback.classic.LoggerContext)6 Logger (ch.qos.logback.classic.Logger)5 Test (org.junit.Test)4 Appender (ch.qos.logback.core.Appender)2 FileAppender (ch.qos.logback.core.FileAppender)2 PatternLayout (ch.qos.logback.classic.PatternLayout)1 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 LayoutWrappingEncoder (ch.qos.logback.core.encoder.LayoutWrappingEncoder)1 BroadcastSession (com.cgbystrom.sockjs.test.BroadcastSession)1 JmxReporter (com.codahale.metrics.JmxReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 Timestamp (java.sql.Timestamp)1 Random (java.util.Random)1