diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-11-18 10:39:53 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-11-18 11:06:39 +0100 |
commit | db80217f161ac24023e50bfb8c5628e436df6584 (patch) | |
tree | 984d5f901e8544737e1f3462c921905932aafd8d /server/sonar-search | |
parent | 1ab47e622a5f138b9d8e060457027a8d2cc30d08 (diff) | |
download | sonarqube-db80217f161ac24023e50bfb8c5628e436df6584.tar.gz sonarqube-db80217f161ac24023e50bfb8c5628e436df6584.zip |
SONAR-8335 support global log level in ES JVM as we do for other JVM
Diffstat (limited to 'server/sonar-search')
-rw-r--r-- | server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java | 3 | ||||
-rw-r--r-- | server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java | 70 |
2 files changed, 66 insertions, 7 deletions
diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java b/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java index 04136ab0698..d0216cc89f6 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchLogging.java @@ -39,8 +39,7 @@ public class SearchLogging { String logPattern = helper.buildLogPattern(config); helper.configureGlobalFileLog(props, config, logPattern); helper.configureForSubprocessGobbler(props, logPattern); - // SQ's global log level must not change ES's log level - helper.configureRootLogLevel(props, "sonar.log.level.es"); + helper.configureRootLogLevel(props, ProcessId.ELASTICSEARCH); return ctx; } diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java index b7f2fa60afd..c1a18209704 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/SearchLoggingTest.java @@ -33,6 +33,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.process.LogbackHelper; import org.sonar.process.ProcessProperties; @@ -44,6 +45,8 @@ import static org.slf4j.Logger.ROOT_LOGGER_NAME; public class SearchLoggingTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + @Rule + public ExpectedException expectedException = ExpectedException.none(); private File logDir; @@ -85,22 +88,79 @@ public class SearchLoggingTest { } @Test - public void root_log_level_does_not_change_with_global_property_value() { + public void default_level_for_root_logger_is_INFO() { + LoggerContext ctx = underTest.configure(props); + + verifyRootLogLevel(ctx, Level.INFO); + } + + @Test + public void root_logger_level_changes_with_global_property() { props.set("sonar.log.level", "TRACE"); LoggerContext ctx = underTest.configure(props); - Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME); - assertThat(rootLogger.getLevel()).isEqualTo(Level.INFO); + verifyRootLogLevel(ctx, Level.TRACE); } @Test - public void root_log_level_change_with_es_property_value() { + public void root_logger_level_changes_with_es_property() { props.set("sonar.log.level.es", "TRACE"); LoggerContext ctx = underTest.configure(props); + verifyRootLogLevel(ctx, Level.TRACE); + } + + @Test + public void root_logger_level_is_configured_from_es_property_over_global_property() { + props.set("sonar.log.level", "TRACE"); + props.set("sonar.log.level.es", "DEBUG"); + + LoggerContext ctx = underTest.configure(props); + + verifyRootLogLevel(ctx, Level.DEBUG); + } + + @Test + public void root_logger_level_changes_with_es_property_and_is_case_insensitive() { + props.set("sonar.log.level.es", "deBug"); + + LoggerContext ctx = underTest.configure(props); + + verifyRootLogLevel(ctx, Level.DEBUG); + } + + @Test + public void root_logger_level_defaults_to_INFO_if_es_property_has_invalid_value() { + props.set("sonar.log.level.es", "DodoDouh!"); + + LoggerContext ctx = underTest.configure(props); + verifyRootLogLevel(ctx, Level.INFO); + } + + @Test + public void fail_with_IAE_if_global_property_unsupported_level() { + props.set("sonar.log.level", "ERROR"); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("log level ERROR in property sonar.log.level is not a supported value (allowed levels are [TRACE, DEBUG, INFO])"); + + underTest.configure(props); + } + + @Test + public void fail_with_IAE_if_es_property_unsupported_level() { + props.set("sonar.log.level.es", "ERROR"); + + expectedException.expect(IllegalArgumentException.class); + expectedException.expectMessage("log level ERROR in property sonar.log.level.es is not a supported value (allowed levels are [TRACE, DEBUG, INFO])"); + + underTest.configure(props); + } + + private void verifyRootLogLevel(LoggerContext ctx, Level expected) { Logger rootLogger = ctx.getLogger(ROOT_LOGGER_NAME); - assertThat(rootLogger.getLevel()).isEqualTo(Level.TRACE); + assertThat(rootLogger.getLevel()).isEqualTo(expected); } } |