BETA Shoulder is in beta — Findings may sometimes be wrong. Your feedback shapes what we fix next. Share feedback

Avoid print() when logging module exists

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)

How to fix

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

Applies to

Languages

Frameworks

flask django fastapi

Scan for this issue

Detect with Shoulder CLI
npx @shoulderdev/cli trust --rule=python-avoid-print-logging .

Related rules