Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize logging #641

Merged
merged 1 commit into from
Oct 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ public UndocumentedApiCheck() {
protected void onPublicApi(AstNode node, String id, List<Token> comments) {
boolean commented = !comments.isEmpty();

LOG.debug("node: " + node.getType() + " line: " + node.getTokenLine()
+ " id: '" + id + "' documented: " + commented);

LOG.debug("node: {} line: {} id: '{}' documented: {}",
new Object[]{node.getType(), node.getTokenLine(), id, commented});
if (!commented) {
getContext().createLineViolation(this, "Undocumented API: " + id,
node);
Expand Down
4 changes: 3 additions & 1 deletion cxx-squid/src/main/java/org/sonar/cxx/CxxConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ public void setCompilationPropertiesWithBuildLog(List<File> reports,

for(File buildLog : reports) {
if (buildLog.exists()) {
LOG.debug("Parse build log file '{}'", buildLog.getAbsolutePath());
if (LOG.isDebugEnabled()) {
LOG.debug("Parse build log file '{}'", buildLog.getAbsolutePath());
}
if (fileFormat.equals("Visual C++")) {
cxxVCppParser.parseVCppLog(buildLog, baseDir, charsetName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ PreprocessorAction handleIfLine(AstNode ast, Token token, String filename) {
} catch (EvaluationException e) {
LOG.error("[{}:{}]: error evaluating the expression {} assume 'true' ...",
new Object[] {filename, token.getLine(), token.getValue()});
LOG.error(e.toString());
LOG.error("{}", e);
state.skipping = false;
}

Expand Down Expand Up @@ -443,7 +443,7 @@ PreprocessorAction handleElIfLine(AstNode ast, Token token, String filename) {
} catch (EvaluationException e) {
LOG.error("[{}:{}]: error evaluating the expression {} assume 'true' ...",
new Object[] {filename, token.getLine(), token.getValue()});
LOG.error(e.toString());
LOG.error("{}", e);
state.skipping = false;
}

Expand Down Expand Up @@ -695,7 +695,7 @@ private int matchArguments(List<Token> tokens, List<Token> arguments) {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void visitNode(AstNode astNode) {
break;
default:
// should not happen
LOG.error("Visiting unknown node: " + astNode.getType());
LOG.error("Visiting unknown node: {}", astNode.getType());
break;
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ private void visitDeclarator(AstNode declarator, AstNode docNode) {
.getFirstDescendant(CxxGrammarImpl.declaratorId);

if (declaratorId == null) {
LOG.error("null declaratorId: " + AstXmlPrinter.print(declarator));
LOG.error("null declaratorId: {}", AstXmlPrinter.print(declarator));
} else {
visitPublicApi(declaratorId, declaratorId.getTokenValue(), comments);
}
Expand Down Expand Up @@ -473,7 +473,7 @@ private void visitMemberDeclarator(AstNode node) {
id = idNode.getTokenValue();
}
else {
LOG.error("Unsupported declarator at " + node.getTokenLine());
LOG.error("Unsupported declarator at {}", node.getTokenLine());
}
}
}
Expand All @@ -491,7 +491,7 @@ private void visitAliasDeclaration(AstNode aliasDeclNode) {
.getFirstDescendant(GenericTokenType.IDENTIFIER);

if (aliasDeclIdNode == null) {
LOG.error("No identifier found at " + aliasDeclNode.getTokenLine());
LOG.error("No identifier found at {}", aliasDeclNode.getTokenLine());
}
else {
// look for block documentation
Expand Down Expand Up @@ -641,14 +641,11 @@ private static boolean isPublicApiMember(AstNode node) {
// default access in classes is private
return false;
default:
LOG.error("isPublicApiMember unhandled case: "
+ enclosingSpecifierNode.getType()
+ " at " + enclosingSpecifierNode.getTokenLine());
LOG.error("isPublicApiMember unhandled case: {} at {}", enclosingSpecifierNode.getType(), enclosingSpecifierNode.getTokenLine());
return false;
}
} else {
LOG.error("isPublicApiMember: failed to get enclosing "
+ "classSpecifier for node at " + node.getTokenLine());
LOG.error("isPublicApiMember: failed to get enclosing classSpecifier for node at {}", node.getTokenLine());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public void init() {
public void visitNode(AstNode node) {
AstNode identifierAst = node.getFirstChild(GenericTokenType.IDENTIFIER);
if( identifierAst != null ) {
CxxGrammarImpl.LOG.warn("[{}:{}]: syntax error, skip '{}'", new Object[] {context.getFile(), node.getToken().getLine(), identifierAst.getTokenValue()});
CxxGrammarImpl.LOG.warn("[{}:{}]: syntax error, skip '{}'",
new Object[] {context.getFile(), node.getToken().getLine(), identifierAst.getTokenValue()});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public CxxPublicApiVisitor(MetricDef publicDocumentedApi,
protected void onPublicApi(AstNode node, String id, List<Token> comments) {
boolean commented = !comments.isEmpty();

LOG.debug("node: " + node.getType() + " line: " + node.getTokenLine()
+ " id: '" + id + "' documented: " + commented);
LOG.debug("node: {} line: {} id: '{}' documented: {}",
new Object[]{node.getType(), node.getTokenLine(), id, commented});

if (handler != null) {
handler.onPublicApi(node, id, comments);
Expand Down
16 changes: 10 additions & 6 deletions cxx-squid/src/test/java/org/sonar/cxx/CxxPublicApiVisitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ public void onPublicApi(AstNode node, String id,
SourceFile file = CxxAstScanner.scanSingleFile(new File(fileName),
visitor);

LOG.debug("#API: " + file.getInt(CxxMetric.PUBLIC_API) + " UNDOC: "
+ file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API));
if (LOG.isDebugEnabled()) {
LOG.debug("#API: {} UNDOC: {}",
file.getInt(CxxMetric.PUBLIC_API), file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API));
}

assertThat(file.getInt(CxxMetric.PUBLIC_API)).isEqualTo(expectedApi);
assertThat(file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API)).isEqualTo(
Expand Down Expand Up @@ -170,8 +172,10 @@ public void onPublicApi(AstNode node, String id,
SourceFile file = CxxAstScanner.scanSingleFile(new File(
"src/test/resources/metrics/public_api.h"), visitor); //

LOG.debug("DOC: " + file.getInt(CxxMetric.PUBLIC_API) + " UNDOC: "
+ file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API));
if (LOG.isDebugEnabled()) {
LOG.debug("DOC: {} UNDOC: {}",
file.getInt(CxxMetric.PUBLIC_API),file.getInt(CxxMetric.PUBLIC_UNDOCUMENTED_API));
}

final Map<String, String> expectedIdCommentMap = new HashMap<String, String>();

Expand Down Expand Up @@ -226,7 +230,7 @@ public void onPublicApi(AstNode node, String id,

// check completeness
for (final String id : expectedIdCommentMap.keySet()) {
LOG.debug("id: " + id);
LOG.debug("id: {}", id);

List<Token> comments = idCommentMap.get(id);

Expand All @@ -243,7 +247,7 @@ public void onPublicApi(AstNode node, String id,

// check correction
for (final String id : idCommentMap.keySet()) {
LOG.debug("id: " + id);
LOG.debug("id: {}", id);

List<Token> comments = idCommentMap.get(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ public void processReport(final Project project, final SensorContext context, Fi

Scanner scanner = new Scanner(report, charset);
Pattern p = Pattern.compile(reportRegEx, Pattern.MULTILINE);
CxxUtils.LOG.debug("Using pattern : '" + p.toString() + "'");
CxxUtils.LOG.debug("Using pattern : '{}'", p);
MatchResult matchres = null;
while (scanner.findWithinHorizon(p, 0) != null) {
matchres = scanner.match();
String filename = matchres.group(1);
String line = matchres.group(2);
String msg = matchres.group(3);
String id = matchres.group(4).replaceAll("=$", "");
CxxUtils.LOG.debug("Scanner-matches file='" + filename + "' line='" + line + "' id='" + id + "' msg=" + msg);
CxxUtils.LOG.debug("Scanner-matches file='{}' line='{}' id='{}' msg={}",
new Object[]{filename, line, id, msg});
warnings.add(new Warning(filename, line, id, msg));
}
scanner.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ protected void processReport(final Project project, final SensorContext context,
final List<CompilerParser.Warning> warnings = new LinkedList<CompilerParser.Warning>();

// Iterate through the lines of the input file
CxxUtils.LOG.info("Scanner '" + parser.key() + "' initialized with report '{}'" + ", CharSet= '" + reportCharset + "'", report);
CxxUtils.LOG.info("Scanner '{}' initialized with report '{}', CharSet= '{}'",
new Object[]{parser.key(), report, reportCharset});
try {
parser.processReport(project, context, report, reportCharset, reportRegEx, warnings);
for(CompilerParser.Warning w : warnings) {
Expand All @@ -132,9 +133,9 @@ protected void processReport(final Project project, final SensorContext context,
}
}
} catch (java.io.FileNotFoundException e) {
CxxUtils.LOG.error("processReport Exception: " + "report.getName" + " - not processed '{}'", e.toString());
CxxUtils.LOG.error("processReport Exception: {} - not processed '{}'", report, e);
} catch (java.lang.IllegalArgumentException e1) {
CxxUtils.LOG.error("processReport Exception: " + "report.getName" + " - not processed '{}'", e1.toString());
CxxUtils.LOG.error("processReport Exception: {} - not processed '{}'", report, e1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@ public void processReport(final Project project, final SensorContext context, Fi

Scanner scanner = new Scanner(report, charset);
Pattern p = Pattern.compile(reportRegEx, Pattern.MULTILINE);
CxxUtils.LOG.info("Using pattern : '" + p.toString() + "'");
CxxUtils.LOG.info("Using pattern : '{}'", p);
MatchResult matchres = null;
while (scanner.findWithinHorizon(p, 0) != null) {
matchres = scanner.match();
String filename = matchres.group(1);
String line = matchres.group(2);
String id = matchres.group(3);
String msg = matchres.group(4);
CxxUtils.LOG.debug("Scanner-matches file='" + filename + "' line='" + line + "' id='" + id + "' msg=" + msg);
CxxUtils.LOG.debug("Scanner-matches file='{}' line='{}' id='{}' msg={}",
new Object[]{filename, line, id, msg});
warnings.add(new Warning(filename, line, id, msg));
}
scanner.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void define(Context context) {
try {
xmlRuleLoader.load(repository, new StringReader(ruleDefs));
} catch (Exception ex) {
CxxUtils.LOG.info("Cannot load rules XML '{}'", ex.getMessage());
CxxUtils.LOG.info("Cannot load rules XML '{}'", ex);
}
}
}
Expand All @@ -68,7 +68,7 @@ public void define(Context context) {
try {
CxxSqaleXmlLoader.load(repository, new StringReader(sqaleDefs));
} catch (Exception ex) {
CxxUtils.LOG.info("Cannot load SQALE XML '{}'", ex.getMessage());
CxxUtils.LOG.info("Cannot load SQALE XML '{}'", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException {
file, line, id, msg);
} else {
CxxUtils.LOG.warn("PC-lint warning ignored: {}", msg);
CxxUtils.LOG.debug("File: " + file + ", Line: " + line + ", ID: "
+ id + ", msg: " + msg);
CxxUtils.LOG.debug("File: {}, Line: {}, ID: {}, msg: {}",
new Object[]{file, line, id, msg});
}
}
} catch (com.ctc.wstx.exc.WstxUnexpectedCharException e) {
CxxUtils.LOG.error("Ignore XML error from PC-lint '{}'", e.toString());
CxxUtils.LOG.error("Ignore XML error from PC-lint '{}'", e);
} catch (com.ctc.wstx.exc.WstxEOFException e) {
CxxUtils.LOG.error("Ignore XML error from PC-lint '{}'", e.toString());
CxxUtils.LOG.error("Ignore XML error from PC-lint '{}'", e);
}
}

Expand All @@ -142,8 +142,7 @@ private String mapMisraRulesToUniqueSonarRules(String msg) {
if (matcher.find()) {
String misraRule = matcher.group(1);
String newKey = "M" + misraRule;
String debugText = "Remap MISRA rule " + misraRule + " to key " + newKey;
CxxUtils.LOG.debug(debugText);
CxxUtils.LOG.debug("Remap MISRA rule {} to key {}", misraRule, newKey);
return newKey;
}
return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void processReport(final Project project, final SensorContext context,
}
} catch (org.jdom.input.JDOMParseException e) {
// when RATS fails the XML file might be incomplete
CxxUtils.LOG.error("Ignore incomplete XML output from RATS '{}'", e.toString());
CxxUtils.LOG.error("Ignore incomplete XML output from RATS '{}'", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public void addFile(InputFile inputFile, Collection<CxxPreprocessor.Include> inc
if (issuable.addIssue(issue))
violationsCount++;
} else {
CxxUtils.LOG.warn("Already created edge from '" + sonarFile.getKey() + "' (line " + include.getLine() + ") to '" + includedFilePath + "'" +
", previous edge from line " + prevIncludeLine);
CxxUtils.LOG.warn("Already created edge from '{}' (line {} to '{}', previous edge from line {}",
new Object[]{sonarFile.getKey(), include.getLine(), includedFilePath, prevIncludeLine});
}
} else if (includedFile == null) {
CxxUtils.LOG.warn("Unable to find resource '" + include.getPath() + "' to create a dependency with '" + sonarFile.getKey() + "'");
CxxUtils.LOG.warn("Unable to find resource '{}' to create a dependency with '{}'", include.getPath(), sonarFile.getKey());
} else if (context.isIndexed(includedFile, false)) {
//Add the dependency in the files graph
FileEdge fileEdge = new FileEdge(sonarFile, includedFile, include.getLine());
Expand All @@ -125,7 +125,9 @@ public void addFile(InputFile inputFile, Collection<CxxPreprocessor.Include> inc
edge.addRootEdge(fileEdge);
}
} else {
CxxUtils.LOG.debug("Skipping dependency to file '{}', because it is'nt part of this project", includedFile.getName());
if (CxxUtils.LOG.isDebugEnabled()) {
CxxUtils.LOG.debug("Skipping dependency to file '{}', because it is'nt part of this project", includedFile.getName());
}
}
}
}
Expand Down Expand Up @@ -158,11 +160,8 @@ public void save() {
Set<Edge> feedbackEdges = cycleDetector.getFeedbackEdgeSet();
int tangles = cycleDetector.getWeightOfFeedbackEdgeSet();

CxxUtils.LOG.info("Project '" + project.getKey() + "'"
+ " Cycles:" + cycles.size()
+ " Feedback cycles:" + feedbackEdges.size()
+ " Tangles:" + tangles
+ " Weight:" + getEdgesWeight(packagesGraph.getEdges(packages)));
CxxUtils.LOG.info("Project '{}' Cycles:{} Feedback cycles:{} Tangles:{} Weight:{}",
new Object[]{project.getKey(), cycles.size(), feedbackEdges.size(), tangles, getEdgesWeight(packagesGraph.getEdges(packages))});

saveViolations(feedbackEdges, packagesGraph);
savePositiveMeasure(project, CoreMetrics.PACKAGE_CYCLES, cycles.size());
Expand Down Expand Up @@ -190,12 +189,9 @@ private void saveDirectory(Directory dir) {
Set<Edge> feedbackEdges = solver.getEdges();
int tangles = solver.getWeightOfFeedbackEdgeSet();

CxxUtils.LOG.info("Directory: '" + dir.getKey() + "'"
+ " Cycles:" + cycles.size()
+ " Feedback cycles:" + feedbackEdges.size()
+ " Tangles:" + tangles
+ " Weight:" + getEdgesWeight(filesGraph.getEdges(files)));

CxxUtils.LOG.info("Directory: '{}' Cycles:{} Feedback cycles:{} Tangles:{} Weight:{}",
new Object[]{dir.getKey(), cycles.size(), feedbackEdges.size(), tangles, getEdgesWeight(filesGraph.getEdges(files))});

savePositiveMeasure(dir, CoreMetrics.FILE_CYCLES, cycles.size());
savePositiveMeasure(dir, CoreMetrics.FILE_FEEDBACK_EDGES, feedbackEdges.size());
savePositiveMeasure(dir, CoreMetrics.FILE_TANGLES, tangles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void define(Context context) {
FileReader reader = new FileReader(userExtensionXml);
xmlRuleLoader.load(repository, reader);
} catch (Exception ex) {
CxxUtils.LOG.info("Cannot Load XML '{}'", ex.getMessage());
CxxUtils.LOG.info("Cannot Load XML '{}'", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ 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);
CxxUtils.LOG.info("Vera++ processes file = {}", name);
SMInputCursor errorCursor = fileCursor.childElementCursor("error");
while (errorCursor.getNext() != null) {
if (!"error".equals(name)) {
Expand All @@ -98,9 +98,11 @@ public void stream(SMHierarchicCursor rootCursor) throws javax.xml.stream.XMLStr
saveUniqueViolation(project, context, CxxVeraxxRuleRepository.KEY,
name, line, source, message);
} else {
CxxUtils.LOG.debug("Error in file '{}', with message '{}'",
if (CxxUtils.LOG.isDebugEnabled()) {
CxxUtils.LOG.debug("Error in file '{}', with message '{}'",
name + "(" + errorCursor.getAttrValue("line") + ")",
errorCursor.getAttrValue("message"));
}
}
}
}
Expand All @@ -109,7 +111,7 @@ public void stream(SMHierarchicCursor rootCursor) throws javax.xml.stream.XMLStr

parser.parse(report);
} catch (com.ctc.wstx.exc.WstxUnexpectedCharException e) {
CxxUtils.LOG.error("Ignore XML error from Veraxx '{}'", e.toString());
CxxUtils.LOG.error("Ignore XML error from Veraxx '{}'", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,9 @@ private Collection<TestFile> lookupTestFiles(Project project, SensorContext cont
for (TestCase tc : testcases) {
tcTotal++;

CxxUtils.LOG.debug("Trying the input file for the testcase '{}' ...", tc.getFullname());
if (CxxUtils.LOG.isDebugEnabled()) {
CxxUtils.LOG.debug("Trying the input file for the testcase '{}' ...", tc.getFullname());
}
InputFile inputFile = lookupFile(project, context, tc);
if (inputFile != null) {
CxxUtils.LOG.debug("... found! The input file is '{}'", inputFile);
Expand Down
Loading