aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-10-21 09:17:48 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-10-21 18:45:43 +0200
commit146b8393422e64b7a8a4be3a894e0ef0f8caca5c (patch)
tree4c496fc0f14771038ef187ff63d7eb2456e9790b /sonar-plugin-api
parent650e27fe4fa121e9f2f845ebe871c37ffd4a9c71 (diff)
downloadsonarqube-146b8393422e64b7a8a4be3a894e0ef0f8caca5c.tar.gz
sonarqube-146b8393422e64b7a8a4be3a894e0ef0f8caca5c.zip
Add the possibility to log a WARN message with an exception
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/BaseLogger.java6
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/log/Logger.java5
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggerTest.java13
3 files changed, 20 insertions, 4 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/BaseLogger.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/BaseLogger.java
index b038925176a..3c19cc5c673 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/BaseLogger.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/BaseLogger.java
@@ -101,6 +101,12 @@ abstract class BaseLogger implements Logger {
}
@Override
+ public void warn(String msg, Throwable throwable) {
+ LogInterceptors.get().log(LoggerLevel.WARN, msg, throwable);
+ doWarn(msg);
+ }
+
+ @Override
public void warn(String msg, @Nullable Object arg) {
LogInterceptors.get().log(LoggerLevel.WARN, msg, arg);
doWarn(msg, arg);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/Logger.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/Logger.java
index 4d5c3470f58..d0a48696ba8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/Logger.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/log/Logger.java
@@ -168,6 +168,11 @@ public interface Logger {
void warn(String msg);
/**
+ * Logs an exception at the WARN level with an accompanying message.
+ */
+ void warn(String msg, Throwable throwable);
+
+ /**
* Logs a WARN parameterized message according to the specified format and argument. Example:
* <code>warn("Value is {}", value)</code>
*/
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggerTest.java
index 7e4d74c684c..920f73e4948 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggerTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/log/ConsoleLoggerTest.java
@@ -19,13 +19,17 @@
*/
package org.sonar.api.utils.log;
+import java.io.PrintStream;
import org.junit.Rule;
import org.junit.Test;
-import java.io.PrintStream;
-
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.startsWith;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
public class ConsoleLoggerTest {
@@ -94,7 +98,8 @@ public class ConsoleLoggerTest {
underTest.warn("message {}", "foo");
underTest.warn("message {} {}", "foo", "bar");
underTest.warn("message {} {} {}", "foo", "bar", "baz");
- verify(stream, times(4)).println(startsWith("WARN "));
+ underTest.warn("message", new IllegalArgumentException());
+ verify(stream, times(5)).println(startsWith("WARN "));
underTest.error("message");
underTest.error("message {}", "foo");