Search in sources :

Example 16 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project spring-boot by spring-projects.

the class DefaultLogbackConfiguration method consoleAppender.

private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) {
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern(resolve(config, "${CONSOLE_LOG_PATTERN}"));
    encoder.setCharset(resolveCharset(config, "${CONSOLE_LOG_CHARSET}"));
    config.start(encoder);
    appender.setEncoder(encoder);
    config.appender("CONSOLE", appender);
    return appender;
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 17 with ConsoleAppender

use of ch.qos.logback.core.ConsoleAppender in project spring-boot by spring-projects.

the class LogbackConfigurationTests method consolePatternCanBeOverridden.

@Test
void consolePatternCanBeOverridden() throws JoranException {
    JoranConfigurator configurator = new JoranConfigurator();
    LoggerContext context = new LoggerContext();
    configurator.setContext(context);
    configurator.doConfigure(new File("src/test/resources/custom-console-log-pattern.xml"));
    Appender<ILoggingEvent> appender = context.getLogger("ROOT").getAppender("CONSOLE");
    assertThat(appender).isInstanceOf(ConsoleAppender.class);
    Encoder<?> encoder = ((ConsoleAppender<?>) appender).getEncoder();
    assertThat(encoder).isInstanceOf(PatternLayoutEncoder.class);
    assertThat(((PatternLayoutEncoder) encoder).getPattern()).isEqualTo("foo");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 18 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 19 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 20 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)

Aggregations

ConsoleAppender (ch.qos.logback.core.ConsoleAppender)38 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)31 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)21 LoggerContext (ch.qos.logback.classic.LoggerContext)19 Logger (ch.qos.logback.classic.Logger)16 Appender (ch.qos.logback.core.Appender)10 FileAppender (ch.qos.logback.core.FileAppender)9 Test (org.junit.Test)8 ThresholdFilter (ch.qos.logback.classic.filter.ThresholdFilter)5 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)5 LayoutWrappingEncoder (ch.qos.logback.core.encoder.LayoutWrappingEncoder)5 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)4 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AsyncAppender (ch.qos.logback.classic.AsyncAppender)2 JoranException (ch.qos.logback.core.joran.spi.JoranException)2 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 PmsConfiguration (net.pms.configuration.PmsConfiguration)2