Simplify ColorFormatter and keep level names when color is off - #18
Merged
Conversation
ESultanik
force-pushed
the
logger-cleanup
branch
from
August 6, 2026 20:16
e4619d0 to
7418cc7
Compare
`ColorFormatter` reached `logging.Formatter` through a `ComposableFormatter` that
wrapped a formatter and forwarded every attribute via `__getattr__`. That returns
`Any`, so type checking was silently disabled on everything it delegated -- to
support one level of composition that was never reused. It now subclasses
`logging.Formatter` directly, with that class's parameters spelled out rather than
forwarded through `*args, **kwargs`, which typed them as `object`.
Behaviour fix: with colour disabled, `format` returned `record.getMessage()` for
*every* level, not just INFO. Redirecting stderr to a file therefore discarded the
level entirely, and an ERROR read as ordinary prose:
use_color=True: '\x1b[0m\x1b[1;31m\x1b[1mERROR \x1b[0m disk full'
use_color=False: 'disk full' # before
use_color=False: 'ERROR disk full' # after
INFO stays bare at either setting, which is the intended conversational case.
Also replaces the `%`-formatting with an `ansi_color()` helper and f-strings, and
corrects the `format(self, *args, **kwargs)` signature to `format(self, record)`.
First tests for this module: 17 cases covering the INFO special case, per-level
colouring, `$LEVELCOLOR` resolving per record, placeholder expansion and
stripping, multi-line continuation markers, and use as a real handler formatter.
`ruff` and `ty` are both clean on it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01367hFob9sd4xpDmVT4uoFy
ESultanik
force-pushed
the
utils-generics
branch
from
August 7, 2026 19:25
5154c48 to
60210ff
Compare
ESultanik
force-pushed
the
logger-cleanup
branch
from
August 7, 2026 19:25
7418cc7 to
0b1ec69
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #17.
ColorFormatterreachedlogging.Formatterthrough aComposableFormatterthat wrapped a formatter and forwarded every attribute via__getattr__. That returnsAny, so type checking was silently disabled on everything it delegated — to support one level of composition that was never reused. It now subclasseslogging.Formatterdirectly, with that class's parameters spelled out rather than forwarded through*args, **kwargs, which typed them asobject.Behaviour fix
With color disabled,
formatreturnedrecord.getMessage()for every level, not just INFO. Redirecting stderr to a file therefore discarded the level entirely, and an ERROR read as ordinary prose:INFO stays bare at either setting, which is the intended conversational case.
Also replaces the
%-formatting with anansi_color()helper and f-strings, and corrects theformat(self, *args, **kwargs)signature toformat(self, record).Verification
First tests for this module: 17 cases covering the INFO special case, per-level coloring,
$LEVELCOLORresolving per record, placeholder expansion and stripping, multi-line continuation markers, and use as a real handler formatter.ruffandtyare both clean on it.🤖 Generated with Claude Code
https://claude.ai/code/session_01367hFob9sd4xpDmVT4uoFy