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