import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.ConsoleAppender;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.encoder.Encoder;
import org.sonar.process.ProcessId;
: helper.createPatternLayoutEncoder(context, buildDepractedLogPatrern(config));
FileAppender<ILoggingEvent> appender = helper.newFileAppender(context, props, DEPRECATION_LOG_FILE_PREFIX, encoder);
+ ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(context, "CONSOLE", encoder);
Logger deprecated = context.getLogger(DEPRECATION_LOGGER_NAME);
deprecated.setAdditive(false);
deprecated.addAppender(appender);
+ deprecated.addAppender(consoleAppender);
}
private static String buildDepractedLogPatrern(RootLoggerConfig config) {
assertThat(fileAppender.getEncoder()).isInstanceOf(LayoutWrappingEncoder.class);
}
+ @Test
+ public void configure_shouldConfigureDeprecatedLoggerWithConsoleAppender() {
+ LoggerContext ctx = underTest.configure(props);
+
+ Logger root = ctx.getLogger("SONAR_DEPRECATION");
+ Appender<ILoggingEvent> appender = root.getAppender("CONSOLE");
+ assertThat(appender).isNotNull();
+ }
+
private void verifyRootLogLevel(LoggerContext ctx, Level expected) {
Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME);
assertThat(rootLogger.getLevel()).isEqualTo(expected);