Skip to content

Commit

Permalink
Merge pull request #821 from jmecosta/reduce-duplicated-logging
Browse files Browse the repository at this point in the history
reduce logging
  • Loading branch information
guwirth committed Apr 9, 2016
2 parents 5fe2462 + 3e4f4c9 commit 50975c2
Show file tree
Hide file tree
Showing 15 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,6 @@ PreprocessorAction handleIncludeLine(AstNode ast, Token token, String filename)
} finally {
currentFileState = globalStateStack.pop();
}
} else {
LOG.debug("[{}:{}]: skipping already included file '{}'", new Object[]{filename, token.getLine(), includedFile});
}

return new PreprocessorAction(1, Lists.newArrayList(Trivia.createSkippedText(token)), new ArrayList<Token>());
Expand Down Expand Up @@ -748,7 +746,7 @@ private int matchArguments(List<Token> tokens, List<Token> arguments) {

rest = match(rest, ")");
} catch (MismatchException me) {
LOG.error("{}", me);
LOG.error("MismatchException : '{}' rest: '{}'", me.getMessage(), rest);
return 0;
}

Expand All @@ -757,6 +755,7 @@ private int matchArguments(List<Token> tokens, List<Token> arguments) {

private List<Token> match(List<Token> tokens, String str) throws MismatchException {
if (!tokens.get(0).getValue().equals(str)) {
LOG.error("Mismatch: expected '" + str + "' got: '" + tokens.get(0).getValue() + "'");
throw new MismatchException("Mismatch: expected '" + str + "' got: '"
+ tokens.get(0).getValue() + "'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.sonar.sslr.api.Grammar;
import com.sonar.sslr.api.Token;
import com.sonar.sslr.impl.Parser;
import org.sonar.cxx.preprocessor.CxxPreprocessor.MismatchException;

public final class ExpressionEvaluator {

Expand Down Expand Up @@ -144,7 +145,8 @@ private BigInteger evalComplexAst(AstNode exprAst) {
} else if ("functionlikeMacro".equals(nodeType)) {
return evalFunctionlikeMacro(exprAst);
} else {
throw new EvaluationException("Unknown expression type '" + nodeType + "'");
LOG.error("'evalComplexAst' Unknown expression type '" + nodeType + "' for AstExt '" + exprAst.getToken() + "', assuming 0");
return BigInteger.ZERO;
}
}

Expand Down Expand Up @@ -421,13 +423,13 @@ BigInteger evalFunctionlikeMacro(AstNode exprAst) {
List<Token> tokens = exprAst.getTokens();
List<Token> restTokens = tokens.subList(1, tokens.size());
String value = preprocessor.expandFunctionLikeMacro(macroName, restTokens);

LOG.trace("expanding '{}' to '{}'", macroName, value);
if (value == null) {
LOG.warn("Undefined functionlike macro '{}' assuming 0", macroName);
if (value == null || "".equals(value)) {
LOG.error("Undefined functionlike macro '{}' assuming 0", macroName);
return BigInteger.ZERO;
}

return value == null ? BigInteger.ZERO : evalToInt(value, exprAst);
return evalToInt(value, exprAst);
}

String stripSuffix(String number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public BullseyeParser(final String baseDir) {
@Override
public void processReport(final Project project, final SensorContext context, File report, final Map<String, CoverageMeasuresBuilder> coverageData)
throws XMLStreamException {
CxxUtils.LOG.info("Parsing 'Bullseye' format");

CxxUtils.LOG.debug("Parsing 'Bullseye' format");
StaxParser topLevelparser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public CoberturaParser(final String baseDir) {
@Override
public void processReport(final Project project, final SensorContext context, File report, final Map<String, CoverageMeasuresBuilder> coverageData)
throws XMLStreamException {
CxxUtils.LOG.info("Parsing 'Cobertura' format");

CxxUtils.LOG.debug("Parsing 'Cobertura' format");
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ private void saveMeasures(SensorContext context,
}
}
} else {
CxxUtils.LOG.warn("Cannot find the file '{}', ignoring coverage measures", filePath);
CxxUtils.LOG.debug("Cannot find the file '{}', ignoring coverage measures", filePath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public VisualStudioParser(final String baseDir) {
@Override
public void processReport(final Project project, final SensorContext context, File report, final Map<String, CoverageMeasuresBuilder> coverageData)
throws XMLStreamException {
CxxUtils.LOG.info("Parsing 'Visual Studio' format");

CxxUtils.LOG.debug("Parsing 'Visual Studio' format");
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public CppcheckParserV1(CxxCppCheckSensor sensor) {
@Override
public void processReport(final Project project, final SensorContext context, File report)
throws javax.xml.stream.XMLStreamException {
CxxUtils.LOG.info("Parsing 'Cppckeck V1' format");

CxxUtils.LOG.debug("Parsing 'Cppcheck V1' format");
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public CppcheckParserV2(CxxCppCheckSensor sensor) {
@Override
public void processReport(final Project project, final SensorContext context, File report)
throws javax.xml.stream.XMLStreamException {
CxxUtils.LOG.info("Parsing 'Cppcheck V2' format");

CxxUtils.LOG.debug("Parsing 'Cppcheck V2' format");
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ protected String reportPathKey() {

@Override
protected void processReport(final Project project, final SensorContext context, File report) throws javax.xml.stream.XMLStreamException {
CxxUtils.LOG.info("Parsing 'other' format");

CxxUtils.LOG.debug("Parsing 'other' format");
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ protected String reportPathKey() {
@Override
protected void processReport(final Project project, final SensorContext context, File report)
throws javax.xml.stream.XMLStreamException {
CxxUtils.LOG.info("Parsing 'PC-Lint' format");

CxxUtils.LOG.debug("Parsing 'PC-Lint' format");
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ protected String reportPathKey() {
@Override
protected void processReport(final Project project, final SensorContext context, File report)
throws org.jdom.JDOMException, java.io.IOException {
CxxUtils.LOG.info("Parsing 'RATS' format");

CxxUtils.LOG.debug("Parsing 'RATS' format");
try {
SAXBuilder builder = new SAXBuilder(false);
Element root = builder.build(report).getRootElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public void analyse(Project project, SensorContext context) {
visitors.toArray(new SquidAstVisitor[visitors.size()]));

scanner.scanFiles(Lists.newArrayList(fs.files(mainFilePredicate)));

Collection<SourceCode> squidSourceFiles = scanner.getIndex().search(new QueryByType(SourceFile.class));
save(squidSourceFiles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,22 @@ public void analyse(Project project, SensorContext context) {
try {
List<File> reports = getReports(settings, fs.baseDir(), reportPathKey());
violationsCount = 0;

for (File report : reports) {
int prevViolationsCount = violationsCount;
CxxUtils.LOG.info("Processing report '{}'", report);
try {
int prevViolationsCount = violationsCount;
processReport(project, context, report);
CxxUtils.LOG.info("{} processed = {}", metric == null ? "Issues" : metric.getName(),
violationsCount - prevViolationsCount);
CxxUtils.LOG.debug("{} processed = {}", metric == null ? "Issues" : metric.getName(),
violationsCount - prevViolationsCount);
} catch (EmptyReportException e) {
CxxUtils.LOG.warn("The report '{}' seems to be empty, ignoring.", report);
}
}

CxxUtils.LOG.info("{} processed = {}", metric == null ? "Issues" : metric.getName(),
violationsCount);

if (metric != null) {
Measure measure = new Measure(metric);
measure.setIntValue(violationsCount);
Expand Down Expand Up @@ -177,13 +180,16 @@ public static List<File> getReports(Settings settings, final File moduleBaseDir,
directoryScanner.setIncludes(includes.toArray(new String[includes.size()]));
directoryScanner.scan();

for (String found : directoryScanner.getIncludedFiles()) {
CxxUtils.LOG.debug("Adding report '{}'", found);
String [] includeFiles = directoryScanner.getIncludedFiles();
CxxUtils.LOG.info("Scanner found '{}' report files", includeFiles.length);
for (String found : includeFiles) {
reports.add(new File(found));
}

if (reports.isEmpty()) {
CxxUtils.LOG.warn("Cannot find a report for '{}'", reportPathPropertyKey);
} else {
CxxUtils.LOG.info("Parser will parse '{}' report files", reports.size());
}
} else {
CxxUtils.LOG.error("Undefined report path value for key '{}'", reportPathPropertyKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected String reportPathKey() {
@Override
protected void processReport(final Project project, final SensorContext context, File report)
throws javax.xml.stream.XMLStreamException {
CxxUtils.LOG.info("Parsing 'Valgrind' format");
CxxUtils.LOG.debug("Parsing 'Valgrind' format");
ValgrindReportParser parser = new ValgrindReportParser();
saveErrors(project, context, parser.processReport(project, context, report));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ protected String reportPathKey() {
@Override
protected void processReport(final Project project, final SensorContext context, File report)
throws javax.xml.stream.XMLStreamException {
CxxUtils.LOG.info("Parsing 'Vera++' format");

CxxUtils.LOG.debug("Parsing 'Vera++' format");
try {
StaxParser parser = new StaxParser(new StaxParser.XmlStreamHandler() {
/**
Expand All @@ -87,7 +86,6 @@ public void stream(SMHierarchicCursor rootCursor) throws javax.xml.stream.XMLStr
while (fileCursor.getNext() != null) {
String name = fileCursor.getAttrValue("name");

CxxUtils.LOG.info("Vera++ processes file = {}", name);
SMInputCursor errorCursor = fileCursor.childElementCursor("error");
while (errorCursor.getNext() != null) {
if (!"error".equals(name)) {
Expand Down

0 comments on commit 50975c2

Please sign in to comment.