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);
    }
}

Remediation

Pass the level explicitly - System.debug(LoggingLevel.ERROR, message) for failures, LoggingLevel.WARN for recoverable conditions, LoggingLevel.FINE or below for traces you only want while debugging.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved