package org.sonar.batch.bootstrapper;
import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.pattern.ExtendedThrowableProxyConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
@Override
protected void append(ILoggingEvent event) {
- target.log(event.getFormattedMessage(), translate(event.getLevel()));
+ if (event.getThrowableProxy() == null) {
+ target.log(event.getFormattedMessage(), translate(event.getLevel()));
+ } else {
+ ExtendedThrowableProxyConverter throwableConverter = new ExtendedThrowableProxyConverter();
+ throwableConverter.start();
+ target.log(event.getFormattedMessage() + "\n" + throwableConverter.convert(event), translate(event.getLevel()));
+ throwableConverter.stop();
+ }
}
private static LogOutput.Level translate(Level level) {
package org.sonar.batch.mediumtest.log;
import com.google.common.collect.ImmutableMap;
-
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.batch.bootstrapper.LogOutput;
+import org.sonar.batch.bootstrapper.LogOutput.Level;
import org.sonar.batch.mediumtest.BatchMediumTester;
import org.sonar.xoo.XooPlugin;
+
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
public class LogListenerTest {
@Rule
}
}
+ // SONAR-7540
+ @Test
+ public void testStackTrace() throws IOException {
+ File srcDir = new File(baseDir, "src");
+ srcDir.mkdir();
+
+ File xooFile = new File(srcDir, "sample.xoo");
+ FileUtils.write(xooFile, "Sample xoo\ncontent");
+ File xooFileMeasure = new File(srcDir, "sample.xoo.measures");
+ FileUtils.write(xooFileMeasure, "foo:bar");
+
+ try {
+ tester.newTask()
+ .properties(builder
+ .put("sonar.sources", "src")
+ .build())
+ .start();
+ fail("Expected exception");
+ } catch (Exception e) {
+ assertThat(e.getMessage()).contains("Error processing line 1");
+ }
+ tester.stop();
+
+ assertNoStdOutput();
+
+ synchronized (logOutput) {
+ for (LogEvent e : logOutput) {
+ if (e.level == Level.ERROR) {
+ assertThat(e.msg).contains("Error processing line 1 of file", "src/sample.xoo.measures", "java.lang.IllegalStateException: Unknow metric with key: foo",
+ "at org.sonar.xoo.lang.MeasureSensor.saveMeasure");
+
+ }
+ }
+ }
+ }
+
private class SimpleLogListener implements LogOutput {
@Override
public void log(String msg, Level level) {