corvix.observability.logging¶
Structured JSON logging for Corvix.
Provides configure_logging(), which installs a single stdout handler on
the root logger emitting one JSON object per line with a consistent schema:
timestamp, level, logger, module, event and any extra
fields passed via logger.*(..., extra={...}).
A contextvars-based context (see bind_log_context()) lets request
scoped fields such as request_id be attached to every log line emitted while
handling a request without threading them through every call.
Attributes¶
Classes¶
Render log records as single-line JSON objects. |
Functions¶
|
|
|
Merge fields into the current logging context and return the previous one. |
|
Restore a logging context previously returned by |
|
|
|
Install the structured logging handler on the root logger. |
Module Contents¶
- corvix.observability.logging._log_context: contextvars.ContextVar[dict[str, object] | None][source][source]¶
- corvix.observability.logging.bind_log_context(**fields: object) dict[str, object] | None[source][source]¶
Merge fields into the current logging context and return the previous one.
The returned value should be passed to
reset_log_context()to restore the prior state (typically in afinallyblock).
- corvix.observability.logging.reset_log_context(previous: dict[str, object] | None) None[source][source]¶
Restore a logging context previously returned by
bind_log_context().
- class corvix.observability.logging.JsonFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source][source]¶
Bases:
logging.FormatterRender log records as single-line JSON objects.
- format(record: logging.LogRecord) str[source][source]¶
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- corvix.observability.logging.configure_logging(level: str | None = None, log_format: str | None = None) None[source][source]¶
Install the structured logging handler on the root logger.
leveldefaults toCORVIX_LOG_LEVEL(thenINFO) andlog_formattoCORVIX_LOG_FORMAT(thenjson;consoleselects a human-readable formatter for local development). Safe to call multiple times — the Corvix handler is only installed once.