Search in sources :

Example 1 with ILoggingEvent

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

the class AppLogging method configureRootWithLogbackWritingToFile.

private void configureRootWithLogbackWritingToFile(LoggerContext ctx) {
    Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
    String appLogPattern = helper.buildLogPattern(APP_ROOT_LOGGER_CONFIG);
    FileAppender<ILoggingEvent> fileAppender = helper.newFileAppender(ctx, appSettings.getProps(), APP_ROOT_LOGGER_CONFIG, appLogPattern);
    rootLogger.addAppender(fileAppender);
    rootLogger.addAppender(createAppConsoleAppender(ctx, appLogPattern));
}
Also used : Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 2 with ILoggingEvent

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

Example 3 with ILoggingEvent

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

the class LogbackHelper method newFileAppender.

public FileAppender<ILoggingEvent> newFileAppender(LoggerContext ctx, Props props, RootLoggerConfig config, String logPattern) {
    RollingPolicy rollingPolicy = createRollingPolicy(ctx, props, config.getProcessId().getLogFilenamePrefix());
    FileAppender<ILoggingEvent> fileAppender = rollingPolicy.createAppender("file_" + config.getProcessId().getLogFilenamePrefix());
    fileAppender.setContext(ctx);
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileEncoder.setContext(ctx);
    fileEncoder.setPattern(logPattern);
    fileEncoder.start();
    fileAppender.setEncoder(fileEncoder);
    fileAppender.start();
    return fileAppender;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 4 with ILoggingEvent

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

the class ServerProcessLogging method configureDirectToConsoleLoggers.

/**
   * Setup one or more specified loggers to be non additive and to print to System.out which will be caught by the Main
   * Process and written to sonar.log.
   */
private void configureDirectToConsoleLoggers(LoggerContext context, String... loggerNames) {
    RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.APP).setThreadIdFieldPattern("").build();
    String logPattern = helper.buildLogPattern(config);
    ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(context, "CONSOLE", logPattern);
    for (String loggerName : loggerNames) {
        Logger consoleLogger = context.getLogger(loggerName);
        consoleLogger.setAdditive(false);
        consoleLogger.addAppender(consoleAppender);
    }
}
Also used : RootLoggerConfig(org.sonar.process.logging.RootLoggerConfig) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Logger(ch.qos.logback.classic.Logger)

Example 5 with ILoggingEvent

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

the class DropwizardSlf4jRequestLogTest method logsRequestsToTheAppenders.

@Test
public void logsRequestsToTheAppenders() throws Exception {
    final ILoggingEvent event = logAndCapture();
    // It would be lovely if the clock could be injected so we could test this reliably, but
    // I suppose we should just trust the Jetty folks.
    assertThat(event.getFormattedMessage()).startsWith("10.0.0.1");
    assertThat(event.getLevel()).isEqualTo(Level.INFO);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)298 Test (org.junit.Test)111 Logger (ch.qos.logback.classic.Logger)89 LoggerContext (ch.qos.logback.classic.LoggerContext)84 Appender (ch.qos.logback.core.Appender)48 Test (org.junit.jupiter.api.Test)47 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)43 FileAppender (ch.qos.logback.core.FileAppender)39 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)35 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)30 File (java.io.File)26 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)22 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)21 Logger (org.slf4j.Logger)20 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)17 AsyncAppender (ch.qos.logback.classic.AsyncAppender)16 ArrayList (java.util.ArrayList)16 ListAppender (ch.qos.logback.core.read.ListAppender)15 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13