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;
private final ThrowableProxyConverter tpc = new ThrowableProxyConverter();
+ public ScannerLogbackEncoder() {
+ tpc.setOptionList(List.of("full"));
+ tpc.start();
+ }
+
@Override
public byte[] headerBytes() {
return EMPTY_BYTES;
import static org.mockito.Mockito.when;
class ScannerLogbackEncoderTest {
-
+
ScannerLogbackEncoder underTest = new ScannerLogbackEncoder();
-
+
@Test
void no_headers_and_footers() {
assertThat(underTest.headerBytes()).isEmpty();
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
+}