]> source.dussan.org Git - sonarqube.git/commitdiff
Fix stacktrace in the Json output
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 7 May 2024 14:17:25 +0000 (16:17 +0200)
committersonartech <sonartech@sonarsource.com>
Mon, 13 May 2024 20:02:41 +0000 (20:02 +0000)
sonar-scanner-engine/src/main/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoder.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerLogbackEncoderTest.java

index bbad390077a0f105e600a0275e14340a4fb61e09..f67b41bf40c2d1e2a73a7e493415e2c1669ddcf7 100644 (file)
@@ -24,6 +24,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.classic.spi.IThrowableProxy;
 import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.encoder.EncoderBase;
+import java.util.List;
 import org.apache.commons.text.StringEscapeUtils;
 
 import static ch.qos.logback.core.CoreConstants.COMMA_CHAR;
@@ -41,6 +42,11 @@ public class ScannerLogbackEncoder extends EncoderBase<ILoggingEvent> {
 
   private final ThrowableProxyConverter tpc = new ThrowableProxyConverter();
 
+  public ScannerLogbackEncoder() {
+    tpc.setOptionList(List.of("full"));
+    tpc.start();
+  }
+
   @Override
   public byte[] headerBytes() {
     return EMPTY_BYTES;
index e63985da428ae1e81fe536b514741c1b4bf7cddd..d752b67b4c5b808873f9c5a648de080d013531e7 100644 (file)
@@ -30,9 +30,9 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 class ScannerLogbackEncoderTest {
-  
+
   ScannerLogbackEncoder underTest = new ScannerLogbackEncoder();
-  
+
   @Test
   void no_headers_and_footers() {
     assertThat(underTest.headerBytes()).isEmpty();
@@ -70,7 +70,9 @@ class ScannerLogbackEncoderTest {
 
     var bytes = underTest.encode(logEvent);
 
-    assertThat(new String(bytes, StandardCharsets.UTF_8)).isEqualTo("{\"level\":\"DEBUG\",\"message\":\"message\",\"stacktrace\":\"java.lang.IllegalArgumentException: foo\\n\"}\n");
+    assertThat(new String(bytes, StandardCharsets.UTF_8))
+      .startsWith(
+        "{\"level\":\"DEBUG\",\"message\":\"message\",\"stacktrace\":\"java.lang.IllegalArgumentException: foo\\n\\tat org.sonar.scanner.bootstrap.ScannerLogbackEncoderTest.should_encode_with_stacktrace");
   }
 
-}
\ No newline at end of file
+}