Search in sources :

Example 71 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project netty by netty.

the class SingleThreadEventLoopTest method testRegistrationAfterShutdown.

@Test(timeout = 10000)
@SuppressWarnings("deprecation")
public void testRegistrationAfterShutdown() throws Exception {
    loopA.shutdown();
    // Disable logging temporarily.
    Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    List<Appender<ILoggingEvent>> appenders = new ArrayList<Appender<ILoggingEvent>>();
    for (Iterator<Appender<ILoggingEvent>> i = root.iteratorForAppenders(); i.hasNext(); ) {
        Appender<ILoggingEvent> a = i.next();
        appenders.add(a);
        root.detachAppender(a);
    }
    try {
        ChannelFuture f = loopA.register(new LocalChannel());
        f.awaitUninterruptibly();
        assertFalse(f.isSuccess());
        assertThat(f.cause(), is(instanceOf(RejectedExecutionException.class)));
        assertFalse(f.channel().isOpen());
    } finally {
        for (Appender<ILoggingEvent> a : appenders) {
            root.addAppender(a);
        }
    }
}
Also used : Appender(ch.qos.logback.core.Appender) LocalChannel(io.netty.channel.local.LocalChannel) ArrayList(java.util.ArrayList) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 72 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarqube by SonarSource.

the class AppLogging method configureConsole.

/**
   * Creates a non additive logger dedicated to printing message as is (ie. assuming they are already formatted).
   *
   * It creates a dedicated appender to the System.out which applies no formatting the logs it receives.
   */
private void configureConsole(LoggerContext loggerContext) {
    ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(loggerContext, CONSOLE_PLAIN_APPENDER, "%msg%n");
    Logger consoleLogger = loggerContext.getLogger(CONSOLE_LOGGER);
    consoleLogger.setAdditive(false);
    consoleLogger.addAppender(consoleAppender);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Logger(ch.qos.logback.classic.Logger)

Example 73 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent 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 74 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent 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 75 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project sonarqube by SonarSource.

the class SearchLoggingTest method log_to_es_file.

@Test
public void log_to_es_file() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(ROOT_LOGGER_NAME);
    Appender<ILoggingEvent> appender = root.getAppender("file_es");
    assertThat(appender).isInstanceOf(FileAppender.class);
    FileAppender fileAppender = (FileAppender) appender;
    assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "es.log").getAbsolutePath());
    assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
    PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
    assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level es[][%logger{20}] %msg%n");
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) 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) File(java.io.File) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)106 Test (org.junit.Test)47 LoggerContext (ch.qos.logback.classic.LoggerContext)37 Logger (ch.qos.logback.classic.Logger)34 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)19 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)18 FileAppender (ch.qos.logback.core.FileAppender)17 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)17 File (java.io.File)15 Appender (ch.qos.logback.core.Appender)12 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)10 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)10 ArrayList (java.util.ArrayList)9 Logger (org.slf4j.Logger)9 LogMessage (co.cask.cdap.logging.appender.LogMessage)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 IOException (java.io.IOException)6 SlingRollingFileAppender (org.apache.sling.commons.log.logback.internal.util.SlingRollingFileAppender)6