]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7574 Allow to set log level to WARN or ERROR in API
authorEric Hartmann <hartmann.eric@gmail.com>
Tue, 10 Oct 2017 12:49:43 +0000 (14:49 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Thu, 12 Oct 2017 08:59:38 +0000 (10:59 +0200)
sonar-plugin-api/src/main/java/org/sonar/api/utils/log/LogbackLogger.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/log/LogbackLoggerTest.java

index cbb3c6b603b319a3a033c8c155cbf156164b6f16..12def9cdef689f3fe2270d6ce22a87ada87458df 100644 (file)
@@ -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;
   }
index 2376a98380b25a48c15d6aad2cb4c69fb851c829..d4e3bc8ae4daa09e5c28a80c79f375f8a5594b13 100644 (file)
@@ -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");
-    }
-
-
-  }
 }