diff --git a/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java b/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java index b002e13fd2..93baaa9655 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/CxxAstScanner.java @@ -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 visitor : visitors) { diff --git a/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxParseErrorLoggerVisitor.java b/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxParseErrorLoggerVisitor.java index 217684fb8d..5ee86aadd0 100644 --- a/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxParseErrorLoggerVisitor.java +++ b/cxx-squid/src/main/java/org/sonar/cxx/visitors/CxxParseErrorLoggerVisitor.java @@ -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; @@ -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); @@ -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; @@ -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()); } }