Skip to content

Log render

log_render

Defines helpers for tokenizing container log lines

Why

docker compose logs streams plain text prefixed with <container> | per line, which breaks the server's styled console log output, making logs harder to read

How It Works
  • This module splits a docker compose logs line into typed (text, kind) segments so a front-end can colour it like the server's styled console handler
Token Types
  • Docker Service Prefix
  • Log Level
  • Uuids
  • Paths
  • Urls
  • Numbers
  • Status Keywords
No Presentation Here
  • Each front-end maps the returned kind to its own palette and builds its own spans

  • Levels are returned as the literal level word so the caller can colour INFO / WARNING / ERROR distinctly

LogKind = Literal['service', 'level', 'uuid', 'url', 'path', 'number', 'ok', 'bad', 'warn', 'plain'] module-attribute

All possible types for a log-line segment

tokenize(line, *, with_service=True)

Splits a container log line into typed segments for themed rendering

Parameters:

Name Type Description Default
line str

A single log line, possibly prefixed by docker compose with <container> |

required
with_service bool

When True, the <container> | prefix is emitted as a service segment so the front-end can highlight it. Pass False when logs are filtered to one service and the prefix is redundant

True

Returns:

Type Description
list[tuple[str, LogKind]]

A list of (text, kind) segments covering the whole line in order