Skip to content

Commit

Permalink
lower the severity of CxxParseErrorLoggerVisitor from WARN to INFO
Browse files Browse the repository at this point in the history
* I profiled our visitors (SonarOpenCommunity#1507) and came to the conclusion,
  that CxxParseErrorLoggerVisitor might require a terrible amount
  of time in order to analyze and to print out all the parsing errors

* The ordinary user should not be interested in the parsing process.
  He/she has no influence on that. Such information is important
  if parsing affects some internal checks or metrics. If user decides
  to submit a bug report, the full debug trace will include the
  parsing errors.

* In general I believe, that our trace is too verbose. So this
  change address this problem too.
  • Loading branch information
ivangalkin committed Oct 2, 2018
1 parent d948649 commit 5fdbbdb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ public SourceCode createSourceCode(SourceCode parentSourceCode, AstNode astNode)
builder.withSquidAstVisitor(new CxxFileVisitor<>(context));

// log syntax errors
builder.withSquidAstVisitor(new CxxParseErrorLoggerVisitor<>(context));
if (CxxParseErrorLoggerVisitor.isLoggingEnabled()) {
builder.withSquidAstVisitor(new CxxParseErrorLoggerVisitor<>(context));
}

/* External visitors (typically Check ones) */
for (SquidAstVisitor<Grammar> visitor : visitors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.sonar.sslr.api.TokenType;
import java.util.List;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.api.utils.log.Loggers;
import org.sonar.cxx.api.CxxPunctuator;
import org.sonar.cxx.parser.CxxGrammarImpl;
Expand All @@ -42,6 +43,15 @@ public CxxParseErrorLoggerVisitor(SquidAstVisitorContext<?> context) {
this.context = context;
}

/**
* This only thing this visitor does is to logs with INFO severity; Disable
* the entire visitor if logging level was set to the level > INFO
*/
public static boolean isLoggingEnabled() {
final LoggerLevel level = LOG.getLevel();
return level == LoggerLevel.TRACE || level == LoggerLevel.DEBUG || level == LoggerLevel.INFO;
}

@Override
public void init() {
subscribeTo(CxxGrammarImpl.recoveredDeclaration);
Expand All @@ -64,7 +74,7 @@ public void visitNode(AstNode node) {
} else if (type.equals(CxxPunctuator.CURLBR_LEFT)) {
// part with CURLBR_LEFT is typically an ignored declaration
if (identifierLine != -1) {
LOG.warn("[{}:{}]: skip declaration: {}",
LOG.info("[{}:{}]: skip declaration: {}",
context.getFile(), identifierLine, sb.toString());
sb.setLength(0);
identifierLine = -1;
Expand All @@ -79,7 +89,7 @@ public void visitNode(AstNode node) {

if (identifierLine != -1 && sb.length() > 0) {
// part without CURLBR_LEFT is typically a syntax error
LOG.warn("[{}:{}]: syntax error: {}",
LOG.info("[{}:{}]: syntax error: {}",
context.getFile(), identifierLine, sb.toString());
}
}
Expand Down

0 comments on commit 5fdbbdb

Please sign in to comment.