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 = {logging.DEBUG: '\x1b[38;5;244m', logging.WARNING: '\x1b[38;5;166m', logging.ERROR: '\x1b[1;38;5;196m', logging.CRITICAL: '\x1b[1;4;38;5;196m'}
LevelColorFormatter
¶
Bases: Formatter
The historical format, the whole line coloured by level when enabled.
_OncePerRecord
¶
Bases: Filter
Lets a record through once per output, however many handlers receive it.
A terminal shows stdout and stderr together, so the two are one output here: a record already written to either is not written to the other. A file or another stream is its own output. It makes "one record, two handlers" harmless whatever installs the handlers.
ConsoleHandler
¶
_StripNamePrefix
¶
Bases: Filter
Drops a message's own tdfs4ds.x: prefix when the format already prints the logger name.
Many server messages start with "tdfs4ds.serve: ..."; the server's format adds
%(name)s: too, which printed tdfs4ds.serve.bootstrap: tdfs4ds.serve: .... Only a
prefix that the record's own logger name already shows is removed.
use_color
¶
Whether a line written now to stream (default stdout) gets a colour.
dedupe_stream_handlers
¶
Put the once-per-record guard on every stream handler of the root logger and of loggers.
Called by the server after it has set up its logging: a handler added by anything else (a library, the host application) writing to the same terminal then cannot repeat a line.
strip_name_prefix
¶
Put :class:_StripNamePrefix on the stream handlers of the root logger and of loggers
(the server's handlers, whose format prints the logger name).
describe_handlers
¶
describe_handlers(names=('', 'tdfs4ds', 'tdfs4ds.serve', 'uvicorn', 'uvicorn.error', 'uvicorn.access', 'gradio')) -> str
The handler layout, one line per logger (for a DEBUG line when a copy shows twice).
configure_logging
¶
Apply the console settings to the tdfs4ds logger.
color / propagate set tdfs4ds.LOG_COLOR / tdfs4ds.LOG_PROPAGATE
first when given. Idempotent: with LOG_PROPAGATE off, exactly one console
handler; on, none (every one is removed), so a record can never be written by
this logger's own handler AND by the root handler.