tdfs4ds.log_output¶
tdfs4ds.log_output
¶
Console output of the tdfs4ds logger: stdout, one colour per level.
Before 0.3.4.2 import tdfs4ds called logging.basicConfig on the ROOT
logger. Two consequences, both seen in notebooks:
- every line went to stderr, which Jupyter shades pink whatever the level, so an INFO looked like an ERROR;
basicConfigdoes nothing once anything else configured the root logger, so in some kernels the lines went through another handler instead (plain black and white). The import order decided which, and the level never did. It also switched on INFO for every other library (httpx's "HTTP Request" lines).
Now the tdfs4ds logger has its own handler: stdout, the historical format,
and the level as a colour (DEBUG grey, INFO plain, WARNING orange, ERROR and
CRITICAL red). The root logger is left alone.
Settings (module attributes, TDFS4DS_* env / .env / JSON):
LOG_COLOR:None= auto (a notebook, or a terminal that shows ANSI colours, andNO_COLORunset),True/Falseto force. Read at each line, so changing it takes effect at once.LOG_PROPAGATE:False(default) = tdfs4ds prints its own lines and does not pass them to the root logger, so they are never printed twice.True= no tdfs4ds console output; the lines go to the application's own logging (root handlers, a file, a collector). Applied byconfigure_logging(), at import and byload_config().
_COLORS
module-attribute
¶
_COLORS = {DEBUG: '\x1b[38;5;244m', WARNING: '\x1b[38;5;166m', ERROR: '\x1b[1;38;5;196m', CRITICAL: '\x1b[1;4;38;5;196m'}
LevelColorFormatter
¶
Bases: Formatter
The historical format, the whole line coloured by level when enabled.
ConsoleHandler
¶
Bases: StreamHandler
Writes to the CURRENT sys.stdout (a notebook or pytest replaces it).
use_color
¶
Whether a line written now to stream (default stdout) gets a colour.
configure_logging
¶
Apply the console settings to the tdfs4ds logger.
color / propagate set tdfs4ds.LOG_COLOR / tdfs4ds.LOG_PROPAGATE
first when given. Idempotent: one console handler at most.