TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/alex-ber/AlexBerUtils/llms.txt
Use this file to discover all available pages before exploring further.
alexber.utils.stdlogging module provides a StreamToLogger adapter and the initStream() helper that replaces a stream (typically sys.stderr or sys.stdout) with a logger-backed object. Every line written to the stream is forwarded to a Python logging.Logger.
This is particularly useful in Docker containers and other environments where application logs must be captured from a single stream.
initStream()
The preferred API for redirecting a stream to a logger.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
logger | logging.Logger | logging.getLogger('stderr') | Logger that receives the stream output. |
logger_level | int or str | logging.ERROR | Level at which lines are logged. Accepts integer constants (logging.INFO) or strings ("INFO"). |
stream_getter | callable | Returns sys.stderr | Supplier that returns the stream to be wrapped. |
stream_setter | callable | Sets sys.stderr | Consumer that installs the wrapped stream. |
adapter_cls | type or str | StreamToLogger | Adapter class to use. Can be a class or a dotted import string. |
As of v0.13.11,
logger_level accepts both string level names ("INFO", "DEBUG") and integer constants (logging.INFO). String values are normalised to uppercase before lookup.StreamToLogger
The adapter class that implements the stream interface and forwards writes to a logger. You generally do not need to instantiate this directly — use initStream() instead.
Constructor parameters
| Parameter | Required | Description |
|---|---|---|
logger | Yes | A logging.Logger or compatible logger object. |
stream | Yes | The original stream being wrapped (sys.stderr, sys.stdout, etc.). Used only for flush(). |
logger_level / log_level | No | Log level. Defaults to logging.DEBUG. |
Methods
write(lines)— Splitslineson newlines and logs each non-empty line atlog_level.flush()— Delegates to the original stream’sflush()method.
Redirecting stderr in Docker
In a Docker container, application logs are typically collected from the container’s stdout/stderr streams. If your application uses Python’slogging module with a file handler or a structured formatter, those logs never reach Docker’s log collector. Redirecting sys.stderr to a logger bridges the gap.
Redirect stderr to the logger
sys.stderr — including unhandled exception tracebacks — is logged through the configured logging system.