# Avoid print() when logging module exists - ID: python-avoid-print-logging - Severity: low - CWE: Insufficient Logging (CWE-778) - Languages: Python - Frameworks: flask, django, fastapi ## Description Detects print() calls when the logging module is used in the codebase. CAPABILITY-GATED: This rule only fires when Python's logging module or a logging library (loguru, structlog) is detected. If the project only uses print(), that's an architectural choice - not a violation. When logging infrastructure exists, print() calls are outliers that should be reviewed: - They bypass structured logging - They don't respect log levels - They can't be easily filtered in production - They go to stdout, not stderr (may interfere with output parsing) ## Remediation Replace print() with the logging module. ```python import logging logger = logging.getLogger(__name__) logger.info("User logged in: %s", user_id) logger.debug("Processing file: %s", filename) logger.error("Failed to connect: %s", error) ``` Learn more: https://shoulder.dev/learn/python/cwe-778/avoid-print-logging ## Related Rules - **Avoid console.log when logging library exists** [low]: - **Insufficient Security Event Logging** [MEDIUM]: