utils

Log utils

Logging utilities.

msgspec_json_renderer() - A JSON Renderer for structlog using msgspec.

Msgspec doesn’t have an API consistent with the stdlib’s json module, which is required for Structlog's JSONRenderer.

EventFilter - A structlog processor that removes keys from the log event if they exist.

class src.server.lib.log.utils.EventFilter(filter_keys: Iterable[str])[source]

Bases: object

Remove keys from the log event.

Add an instance to the processor chain.

Example: # noqa

structlog.configure(
    ...,
    processors=[
        ...,
        EventFilter(["color_message"]),
        ...,
    ],
)

Initialize the processor.

Parameters:

filter_keys – Iterable of string keys to be excluded from the log event.

Returns:

None

__init__(filter_keys: Iterable[str]) None[source]

Initialize the processor.

Parameters:

filter_keys – Iterable of string keys to be excluded from the log event.

Returns:

None

__call__(_: WrappedLogger, __: str, event_dict: EventDict) EventDict[source]

Receive the log event, and filter keys.

Parameters:
  • _

  • __

  • event_dict – The data to be logged.

Returns:

The log event with any key in self.filter_keys removed.

src.server.lib.log.utils.msgspec_json_renderer(_: WrappedLogger, __: str, event_dict: EventDict) bytes[source]

Structlog processor that uses msgspec for JSON encoding.

Parameters:
  • _

  • __

  • event_dict – The data to be logged.

Returns:

The log event encoded to JSON by msgspec.