aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-application
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-01-11 09:34:12 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-01-13 13:42:44 +0100
commitb5503ffd8f4aa3654f4589981810ddd0490ae40d (patch)
tree469a0f97f07f91c1f7b0c730ea845853b0e03adc /sonar-application
parente24f76490ae02b8138ad76bce61035132a3ef9a9 (diff)
downloadsonarqube-b5503ffd8f4aa3654f4589981810ddd0490ae40d.tar.gz
sonarqube-b5503ffd8f4aa3654f4589981810ddd0490ae40d.zip
SONAR-7168 add property to change log level of sonar-application
property sonar.app.log.level must either be specifid as a command line argument with -D option or in wrapper.conf as a property such as "wrapper.java.additional.1=-Dsonar.app.log.level=TRACE"
Diffstat (limited to 'sonar-application')
-rw-r--r--sonar-application/src/main/java/org/sonar/application/AppLogging.java6
-rw-r--r--sonar-application/src/test/java/org/sonar/application/AppLoggingTest.java40
2 files changed, 40 insertions, 6 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/AppLogging.java b/sonar-application/src/main/java/org/sonar/application/AppLogging.java
index c1c03bd221d..25c2a3eecdd 100644
--- a/sonar-application/src/main/java/org/sonar/application/AppLogging.java
+++ b/sonar-application/src/main/java/org/sonar/application/AppLogging.java
@@ -50,7 +50,7 @@ class AppLogging {
helper.enableJulChangePropagation(ctx);
configureConsole(ctx);
configureGobbler(props, ctx);
- configureRoot(ctx);
+ configureRoot(props, ctx);
if (props.valueAsBoolean("sonar.log.console", false)) {
// used by SonarSource testing environment
copyGobblerToConsole();
@@ -94,10 +94,10 @@ class AppLogging {
gobblerLogger.addAppender(fileAppender);
}
- private void configureRoot(LoggerContext loggerContext) {
+ private void configureRoot(Props props, LoggerContext loggerContext) {
ConsoleAppender<ILoggingEvent> consoleAppender = helper.newConsoleAppender(loggerContext, "ROOT_CONSOLE", APP_PATTERN, null);
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
- rootLogger.setLevel(Level.INFO);
+ rootLogger.setLevel(Level.toLevel(props.value("sonar.app.log.level", Level.INFO.toString()), Level.INFO));
rootLogger.addAppender(consoleAppender);
}
}
diff --git a/sonar-application/src/test/java/org/sonar/application/AppLoggingTest.java b/sonar-application/src/test/java/org/sonar/application/AppLoggingTest.java
index 33686843a1a..172e6265a5a 100644
--- a/sonar-application/src/test/java/org/sonar/application/AppLoggingTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/AppLoggingTest.java
@@ -19,12 +19,15 @@
*/
package org.sonar.application;
+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.Appender;
import ch.qos.logback.core.FileAppender;
import ch.qos.logback.core.rolling.RollingFileAppender;
+import java.io.File;
+import java.util.Properties;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
@@ -34,9 +37,6 @@ import org.sonar.process.LogbackHelper;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
-import java.io.File;
-import java.util.Properties;
-
import static org.assertj.core.api.Assertions.assertThat;
public class AppLoggingTest {
@@ -91,4 +91,38 @@ public class AppLoggingTest {
assertThat(gobbler.getAppender(AppLogging.GOBBLER_APPENDER)).isNotNull();
assertThat(gobbler.getAppender(AppLogging.CONSOLE_APPENDER)).isNotNull();
}
+
+ @Test
+ public void default_level_for_root_logger_is_INFO() {
+ LoggerContext ctx = underTest.configure(props);
+ Logger rootLogger = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
+ assertThat(rootLogger.getLevel()).isEqualTo(Level.INFO);
+ }
+
+ @Test
+ public void root_logger_level_can_be_changed_with_a_property() {
+ props.set("sonar.app.log.level", "TRACE");
+
+ LoggerContext ctx = underTest.configure(props);
+ Logger rootLogger = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
+ assertThat(rootLogger.getLevel()).isEqualTo(Level.TRACE);
+ }
+
+ @Test
+ public void property_changing_root_logger_level_is_case_insensitive() {
+ props.set("sonar.app.log.level", "trace");
+
+ LoggerContext ctx = underTest.configure(props);
+ Logger rootLogger = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
+ assertThat(rootLogger.getLevel()).isEqualTo(Level.TRACE);
+ }
+
+ @Test
+ public void default_to_INFO_if_property_changing_root_logger_level_has_invalid_value() {
+ props.set("sonar.app.log.level", "DodoDouh!");
+
+ LoggerContext ctx = underTest.configure(props);
+ Logger rootLogger = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
+ assertThat(rootLogger.getLevel()).isEqualTo(Level.INFO);
+ }
}