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));
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations