diff --git a/crates/ruff/resources/test/fixtures/flake8_logging_format/G004.py b/crates/ruff/resources/test/fixtures/flake8_logging_format/G004.py index abbbe8b7d0..56e005293a 100644 --- a/crates/ruff/resources/test/fixtures/flake8_logging_format/G004.py +++ b/crates/ruff/resources/test/fixtures/flake8_logging_format/G004.py @@ -3,3 +3,6 @@ import logging name = "world" logging.info(f"Hello {name}") logging.log(logging.INFO, f"Hello {name}") + +_LOGGER = logging.getLogger() +_LOGGER.info(f"{__name__}") diff --git a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap index b94da46ca9..b54d2a4862 100644 --- a/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap +++ b/crates/ruff/src/rules/flake8_logging_format/snapshots/ruff__rules__flake8_logging_format__tests__G004.py.snap @@ -15,6 +15,15 @@ G004.py:5:27: G004 Logging statement uses f-string 4 | logging.info(f"Hello {name}") 5 | logging.log(logging.INFO, f"Hello {name}") | ^^^^^^^^^^^^^^^ G004 +6 | +7 | _LOGGER = logging.getLogger() + | + +G004.py:8:14: G004 Logging statement uses f-string + | +7 | _LOGGER = logging.getLogger() +8 | _LOGGER.info(f"{__name__}") + | ^^^^^^^^^^^^^ G004 | diff --git a/crates/ruff_python_semantic/src/analyze/logging.rs b/crates/ruff_python_semantic/src/analyze/logging.rs index 70efd2e688..205e3bb8e4 100644 --- a/crates/ruff_python_semantic/src/analyze/logging.rs +++ b/crates/ruff_python_semantic/src/analyze/logging.rs @@ -49,7 +49,13 @@ pub fn is_logger_candidate( // logger names. if let Some(call_path) = collect_call_path(value) { if let Some(tail) = call_path.last() { - if tail.starts_with("log") || tail.ends_with("logger") || tail.ends_with("logging") { + if tail.starts_with("log") + || tail.ends_with("logger") + || tail.ends_with("logging") + || tail.starts_with("LOG") + || tail.ends_with("LOGGER") + || tail.ends_with("LOGGING") + { return true; } }