Skip to content

Logging rules not flagged if logger imported from another module #5694

@petermattia

Description

@petermattia

I'm observing that logging rules aren't flagged if a logger is imported from another module.

  • A minimal code snippet that reproduces the bug.

If I set up logging here, both of these violations are flagged:

# logging_setup.py
import logging

linter = "ruff"
logging.info(f"Hello, {linter}!") # G004 flagged

logger = logging.getLogger(__name__)

logger.info(f"Hello, {linter}!") # G004 flagged

However, if I import logger into another module, the below identical violation is not flagged:

# my_module.py
from logging_setup import logger

linter = "ruff"
logger.info(f"Hello, {linter}!") # G004 *not* flagged
  • The command you invoked (e.g., ruff /path/to/file.py --fix), ideally including the --isolated flag.

ruff .

  • The current Ruff settings (any relevant sections from your pyproject.toml).

"G" ruleset

  • The current Ruff version (ruff --version).
    0.0.277

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions