I'm trying to write a customized java rule to avoid excessive logging. Therefore the log levels must be checked. If the log level check has been forgotten, the rule should report an issue.
package org.sonar.samples.java.checks;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
public class CheckDebugTraceLevel {
private static final Log LOG = LogFactory.getLog(CheckDebugTraceLevel.class);
public void foo()
{
LOG.debug("some debug text.."); // Noncompliant
LOG.trace("some text.."); // Noncompliant
if(LOG.isDebugEnabled()) {
LOG.debug("some debug text..");
}
if(LOG.isTraceEnabled()) {
LOG.trace("some text..");
}
}
}
My question is how to request the if-statement with its condition in my SonarQube custom rule. If somebody could please help, I would really appreciate it.
Aucun commentaire:
Enregistrer un commentaire