System.debug called without a logging level
ID |
apex.maintainability.debug_logging_level |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Logging |
Language |
Apex |
Description
Reports a System.debug call that passes only a message, with no LoggingLevel as its first argument.
Rationale
Without an explicit level the statement is logged at DEBUG, so it cannot be filtered: a log collected at ERROR to find a failure carries every routine trace in the transaction, and the 20 MB debug-log cap truncates exactly the part someone needed. Naming the level is also the only way the statement says how important it is - LoggingLevel.ERROR marks a real problem where a bare call marks nothing.
The following code illustrates the pattern detected by this rule:
public class DebugLevels {
public void run(Account a) {
// FLAGGED: System.debug called without a logging level
System.debug('processing ' + a.Name);
// FLAGGED: System.debug called without a logging level
System.debug(a);
System.debug(LoggingLevel.ERROR, 'processing failed for ' + a.Name);
System.debug(LoggingLevel.FINE, a);
}
}