refactor(logs): name every logger after its module, and hold it there
25 literal names covered 34 modules. plex/client.py, plex/stream.py, plex/subtitles.py, plex/sync.py and two Plex route modules all called themselves `siftlode.plex`; downloads/pipeline.py called itself `siftlode.worker`; routes/channels.py called itself `siftlode.api`. The `logger` column is in every stored row so E22.6's console can filter on it, and so an operator can pin a level to one part of the system — neither works when six modules share a name. `logs.get_logger(__name__)` derives it: app/plex/sync.py -> siftlode.plex.sync. One name per module, and it cannot drift from the file it sits in. tests/test_logger_names.py pins the derivation, that everything stays under the one `siftlode` tree the handler and the tests attach to, and that no module hand-rolls a name again unless the line says why (`# logger-name-ok: <why>`). Two do: get_logger's own call, and `siftlode.http`, which is named for the traffic it carries rather than the module it lives in — it replaced uvicorn's access log and is what an operator pins when they want request lines and nothing else. app/scheduler.py called its logger `logger`; every other module calls it `log`. ruff gains LOG, G, T20, TRY400, TRY401 and S112. Four findings cleared with them: worker.py logged `str(exc)[:120]` where the traceback was the whole question, and three prints/f-strings that are deliberate now say so on the line. S110 and BLE001 stay off until S3 — 23 handlers are outstanding and each is a judgement about one of them; enabling the rules first would just mean 23 blanket noqas.
This commit is contained in:
@@ -9,4 +9,19 @@
|
||||
line-length = 100
|
||||
|
||||
[lint]
|
||||
# Beyond the default set, the rules that hold a LOG LINE to what E22.5 makes of it:
|
||||
# LOG — stdlib logging misuse (`.warn()`, a logger built by hand, `exc_info` on `.exception`)
|
||||
# G — the call's shape: %-style args, never an f-string the level filter cannot skip, and
|
||||
# never `str(exc)` where `exc_info` would carry the traceback
|
||||
# T20 — `print` instead of a log line. Two deliberate ones remain, each with its `# noqa`
|
||||
# and a why: `downloads/runner.py` prints before logging is configured, and
|
||||
# `logsink.py` reports the SINK's own failure, which cannot be logged into the sink.
|
||||
# TRY400 — `.error()` in an `except` where `.exception()` would keep the traceback
|
||||
# TRY401 — the exception spelled into the message AND passed as `exc_info` (it is in both)
|
||||
# S112 — `except: continue`, the silent swallow inside a loop
|
||||
# S110 (`except: pass`) and BLE001 (blind `except Exception`) are NOT here yet: 5 and 18 sites are
|
||||
# outstanding, and each is a judgement about one handler — E22.5 S3 rules on them and turns the two
|
||||
# rules on in the same commit. A rule enabled ahead of that work is a rule enabled with 23 blanket
|
||||
# `noqa`s, which is worse than no rule.
|
||||
extend-select = ["LOG", "G", "T20", "TRY400", "TRY401", "S112"]
|
||||
ignore = ["E402"]
|
||||
|
||||
Reference in New Issue
Block a user