diff options
author | Eric Hartmann <hartmann.eric@gmail.com> | 2017-10-10 14:49:43 +0200 |
---|---|---|
committer | Eric Hartmann <hartmann.eric@gmail.Com> | 2017-10-12 10:59:38 +0200 |
commit | b084faad25e6f601ac90d993379c799d6500e98f (patch) | |
tree | 6f00cc075486cb7f16cc6212e439c3ee192fd7df | |
parent | 97b33c59ada3e65c74b2acb3922f8563a2e53eac (diff) | |
download | sonarqube-b084faad25e6f601ac90d993379c799d6500e98f.tar.gz sonarqube-b084faad25e6f601ac90d993379c799d6500e98f.zip |
SONAR-7574 Allow to set log level to WARN or ERROR in API
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogbackLogger.java | 8 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java | 23 |
2 files changed, 17 insertions, 14 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogbackLogger.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogbackLogger.java index cbb3c6b603b..12def9cdef6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogbackLogger.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogbackLogger.java @@ -167,8 +167,14 @@ class LogbackLogger extends BaseLogger { case INFO: logback.setLevel(Level.INFO); break; + case WARN: + logback.setLevel(Level.WARN); + break; + case ERROR: + logback.setLevel(Level.ERROR); + break; default: - throw new IllegalArgumentException("Only TRACE, DEBUG and INFO logging levels are supported. Got: " + level); + throw new IllegalArgumentException("Only TRACE, DEBUG, INFO , WARN, ERROR logging levels are supported. Got: " + level); } return true; } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java index 2376a98380b..d4e3bc8ae4d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java @@ -67,6 +67,16 @@ public class LogbackLoggerTest { @Test public void change_level() { + assertThat(underTest.setLevel(LoggerLevel.ERROR)).isTrue(); + assertThat(underTest.isDebugEnabled()).isFalse(); + assertThat(underTest.isTraceEnabled()).isFalse(); + assertThat(underTest.logbackLogger().getLevel()).isEqualTo(Level.ERROR); + + assertThat(underTest.setLevel(LoggerLevel.WARN)).isTrue(); + assertThat(underTest.isDebugEnabled()).isFalse(); + assertThat(underTest.isTraceEnabled()).isFalse(); + assertThat(underTest.logbackLogger().getLevel()).isEqualTo(Level.WARN); + assertThat(underTest.setLevel(LoggerLevel.INFO)).isTrue(); assertThat(underTest.logbackLogger().getLevel()).isEqualTo(Level.INFO); assertThat(underTest.isDebugEnabled()).isFalse(); @@ -82,17 +92,4 @@ public class LogbackLoggerTest { assertThat(underTest.isTraceEnabled()).isTrue(); assertThat(underTest.logbackLogger().getLevel()).isEqualTo(Level.TRACE); } - - @Test - public void info_level_can_not_be_disabled() { - try { - underTest.setLevel(LoggerLevel.ERROR); - fail(); - - } catch (IllegalArgumentException e) { - assertThat(e).hasMessage("Only TRACE, DEBUG and INFO logging levels are supported. Got: ERROR"); - } - - - } } |