Search in sources :

Example 16 with LoggerContext

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

the class AppLoggingTest method gobbler_logger_writes_to_console_without_formatting_when_running_from_sonar_script.

@Test
public void gobbler_logger_writes_to_console_without_formatting_when_running_from_sonar_script() {
    emulateRunFromSonarScript();
    LoggerContext ctx = underTest.configure();
    Logger gobblerLogger = ctx.getLogger(LOGGER_GOBBLER);
    verifyGobblerConsoleAppender(gobblerLogger);
    assertThat(gobblerLogger.iteratorForAppenders()).hasSize(1);
}
Also used : Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 17 with LoggerContext

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

the class AppLoggingTest method root_logger_level_changes_with_app_property.

@Test
public void root_logger_level_changes_with_app_property() {
    settings.getProps().set("sonar.log.level.app", "TRACE");
    LoggerContext ctx = underTest.configure();
    verifyRootLogLevel(ctx, Level.TRACE);
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 18 with LoggerContext

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

the class AppLoggingTest method configure_no_rotation_on_sonar_file.

@Test
public void configure_no_rotation_on_sonar_file() {
    settings.getProps().set("sonar.log.rollingPolicy", "none");
    LoggerContext ctx = underTest.configure();
    Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
    Appender<ILoggingEvent> appender = rootLogger.getAppender("file_sonar");
    assertThat(appender).isNotInstanceOf(RollingFileAppender.class).isInstanceOf(FileAppender.class);
}
Also used : RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 19 with LoggerContext

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

the class LogbackHelper method configureForSubprocessGobbler.

/**
   * Make the logback configuration for a sub process to correctly push all its logs to be read by a stream gobbler
   * on the sub process's System.out.
   *
   * @see #buildLogPattern(RootLoggerConfig)
   */
public void configureForSubprocessGobbler(Props props, String logPattern) {
    if (isAllLogsToConsoleEnabled(props)) {
        LoggerContext ctx = getRootContext();
        ctx.getLogger(ROOT_LOGGER_NAME).addAppender(newConsoleAppender(ctx, "root_console", logPattern));
    }
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 20 with LoggerContext

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

the class LogbackHelper method configureGlobalFileLog.

/**
   * Make logback configuration for a process to push all its logs to a log file.
   * <p>
   * <ul>
   * <li>the file's name will use the prefix defined in {@link RootLoggerConfig#getProcessId()#getLogFilenamePrefix()}.</li>
   * <li>the file will follow the rotation policy defined in property {@link #ROLLING_POLICY_PROPERTY} and
   * the max number of files defined in property {@link #MAX_FILES_PROPERTY}</li>
   * <li>the logs will follow the specified log pattern</li>
   * </ul>
   * </p>
   *
   * @see #buildLogPattern(RootLoggerConfig)
   */
public FileAppender<ILoggingEvent> configureGlobalFileLog(Props props, RootLoggerConfig config, String logPattern) {
    LoggerContext ctx = getRootContext();
    Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
    FileAppender<ILoggingEvent> fileAppender = newFileAppender(ctx, props, config, logPattern);
    rootLogger.addAppender(fileAppender);
    return fileAppender;
}
Also used : Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)200 Test (org.junit.Test)133 Logger (ch.qos.logback.classic.Logger)39 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)39 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)21 FileAppender (ch.qos.logback.core.FileAppender)19 File (java.io.File)18 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)15 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)15 Appender (ch.qos.logback.core.Appender)14 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)13 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 JoranException (ch.qos.logback.core.joran.spi.JoranException)10 IOException (java.io.IOException)7 Logger (org.slf4j.Logger)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 ArrayList (java.util.ArrayList)6