Search in sources :

Example 86 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 87 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 88 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)

Example 89 with ILoggingEvent

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

the class LogCollector method init.

private String init(Level filterLevel) {
    StringBuilder sb = new StringBuilder();
    int length = getLength();
    for (int i = 0; i < length; i++) {
        ILoggingEvent event = get(i);
        if (event.getLevel().isGreaterOrEqual(filterLevel)) {
            sb.append(layout.doLayout(event));
        }
    }
    return sb.toString();
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 90 with ILoggingEvent

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

the class LoggerInitializerTest method testInitLoggerContextFromIncludeFolder.

@Test
public void testInitLoggerContextFromIncludeFolder() throws Throwable {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    Logger root = context.getLogger("root");
    Logger sakuliLogger = context.getLogger("org.sakuli");
    Appender<ILoggingEvent> stdout = root.getAppender("stdout");
    Appender<ILoggingEvent> sakuliAppender = root.getAppender("sakuli");
    //no log config in classpath
    Assert.assertNull(stdout);
    Assert.assertNull(sakuliAppender);
    Assert.assertNotNull(sakuliLogger);
    Assert.assertNotNull(root);
    when(sakuliProperties.getConfigFolder()).thenReturn(Paths.get(BaseTest.SAKULI_HOME_FOLDER_PATH + SakuliProperties.CONFIG_FOLDER_APPEDER));
    testling.initLoggerContext();
    verify(testling).getConfigFileFromClasspath();
    verify(testling).getConfigFile();
    //verify root logger
    context = (LoggerContext) LoggerFactory.getILoggerFactory();
    root = context.getLogger("root");
    sakuliLogger = context.getLogger("org.sakuli");
    stdout = root.getAppender("stdout");
    sakuliAppender = root.getAppender("sakuli");
    Assert.assertNotNull(stdout);
    Assert.assertNotNull(sakuliLogger);
    Assert.assertNotNull(sakuliAppender);
    Assert.assertNotNull(sakuliAppender);
}
Also used : Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) BaseTest(org.sakuli.BaseTest) Test(org.testng.annotations.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)121 Test (org.junit.Test)53 Logger (ch.qos.logback.classic.Logger)44 LoggerContext (ch.qos.logback.classic.LoggerContext)41 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)23 FileAppender (ch.qos.logback.core.FileAppender)21 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)18 File (java.io.File)18 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)17 Appender (ch.qos.logback.core.Appender)15 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)14 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)10 ArrayList (java.util.ArrayList)10 Logger (org.slf4j.Logger)10 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)7 LogMessage (co.cask.cdap.logging.appender.LogMessage)7 IOException (java.io.IOException)6 Query (org.apache.lucene.search.Query)6