]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-21227 Expose deprecation.log to console
authorJacek Poreda <jacek.poreda@sonarsource.com>
Thu, 4 Jan 2024 12:16:35 +0000 (13:16 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 4 Jan 2024 20:02:47 +0000 (20:02 +0000)
server/sonar-webserver-core/src/main/java/org/sonar/server/app/WebServerProcessLogging.java
server/sonar-webserver-core/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java

index b3bfdf3a06ecedfe4bd42bd00671d9f32c74650b..6a8536b9b959f139660843335af36a047fb67c16 100644 (file)
@@ -23,6 +23,7 @@ import ch.qos.logback.classic.Level;
 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;
@@ -80,10 +81,12 @@ public class WebServerProcessLogging extends ServerProcessLogging {
       : 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) {
index 35d9ee15e17dc5606f05c4aecc39241156694234..d09fbad5d47f6d722ae6a5829e8fc6dc32d20b13 100644 (file)
@@ -558,6 +558,15 @@ public class WebServerProcessLoggingTest {
     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);