props.setProperty("sonar.verbose", "true");
debugEnabled = true;
logger.setDebugEnabled(true);
- logger.setDisplayStackTrace(true);
} else if ("-D".equals(arg) || "--define".equals(arg)) {
i++;
public class Logs {
private DateTimeFormatter timeFormatter;
private boolean debugEnabled = false;
- private boolean displayStackTrace = false;
private PrintStream stdOut;
private PrintStream stdErr;
this.debugEnabled = debugEnabled;
}
- public void setDisplayStackTrace(boolean displayStackTrace) {
- this.displayStackTrace = displayStackTrace;
- }
-
public boolean isDebugEnabled() {
return debugEnabled;
}
public void error(String message, Throwable t) {
print(stdErr, "ERROR: " + message);
- if (t != null && displayStackTrace) {
+ if (t != null) {
t.printStackTrace(stdErr);
}
}
|| "DEBUG".equalsIgnoreCase(props.getProperty("sonar.log.level"))
|| "TRACE".equalsIgnoreCase(props.getProperty("sonar.log.level"))) {
logger.setDebugEnabled(true);
- logger.setDisplayStackTrace(true);
}
}
@Test
public void testError() {
Exception e = new NullPointerException("exception");
- logs.setDisplayStackTrace(false);
logs.error("error1");
verify(stdErr).println("ERROR: error1");
logs.error("error2", e);
verify(stdErr).println("ERROR: error2");
-
- verifyNoMoreInteractions(stdOut, stdErr);
-
- logs.setDisplayStackTrace(true);
- logs.error("error3", e);
- verify(stdErr).println("ERROR: error3");
+ verify(stdErr).println(e);
// other interactions to print the exception..
}
// Logger used for callback should have debug enabled
verify(logs).setDebugEnabled(true);
- verify(logs).setDisplayStackTrace(true);
ArgumentCaptor<Properties> propertiesCapture = ArgumentCaptor.forClass(Properties.class);
verify(runner).runAnalysis(propertiesCapture.capture());