From 8fd8c030e7dda6eb03c83eb4e59474f5e2d4e401 Mon Sep 17 00:00:00 2001 From: Jacek Poreda Date: Thu, 4 Jan 2024 13:16:35 +0100 Subject: [PATCH] SONAR-21227 Expose deprecation.log to console --- .../org/sonar/server/app/WebServerProcessLogging.java | 3 +++ .../sonar/server/app/WebServerProcessLoggingTest.java | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/app/WebServerProcessLogging.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/app/WebServerProcessLogging.java index b3bfdf3a06e..6a8536b9b95 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/app/WebServerProcessLogging.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/app/WebServerProcessLogging.java @@ -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 appender = helper.newFileAppender(context, props, DEPRECATION_LOG_FILE_PREFIX, encoder); + ConsoleAppender 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) { diff --git a/server/sonar-webserver-core/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java b/server/sonar-webserver-core/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java index 35d9ee15e17..d09fbad5d47 100644 --- a/server/sonar-webserver-core/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java +++ b/server/sonar-webserver-core/src/test/java/org/sonar/server/app/WebServerProcessLoggingTest.java @@ -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 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); -- 2.39.5