Logging info
Logging processors for structlog.
Inspired by: https://ouassim.tech/notes/setting-up-structured-logging-in-fastapi-with-structlog/
| CLASS | DESCRIPTION |
|---|---|
Development |
The development logging configuration. |
LoggerConfig |
The configuration of a logger. |
Logging |
Customized implementation inspired by the following documentation. |
Production |
The production logging configuration. |
| FUNCTION | DESCRIPTION |
|---|---|
configure |
Configure structlog and standard Python logging for structured logging. |
drop_color_message_key |
Drop the |
edit_event_name |
Edit the event dict to change the event name, so we don't clobber elastic indices. |
generate_correlation_id |
Generate a value that is unique for each request. |
tracer_injection |
Inject the current trace and span ids into the event dictionary. |
Classes¶
Development
¶
Bases: Logging[ConsoleRenderer]
The development logging configuration.
| METHOD | DESCRIPTION |
|---|---|
get_renderer |
Return the console renderer for the development environment. |
LoggerConfig
typed-dict
¶
LoggerConfig(*, level: str = ..., propagate: bool = ..., handlers: list[str] = ..., extra: dict = ...)
Bases: TypedDict
The configuration of a logger.
| PARAMETER | DESCRIPTION |
|---|---|
level
|
TYPE:
|
propagate
|
TYPE:
|
handlers
|
TYPE:
|
extra
|
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
level
|
TYPE:
|
propagate
|
TYPE:
|
handlers
|
|
extra
|
TYPE:
|
Functions¶
Logging
¶
Bases: Generic[RendererType]
Customized implementation inspired by the following documentation.
| METHOD | DESCRIPTION |
|---|---|
configure |
Configure structlog and standard Python logging for structured logging. |
configure_stdlib |
Configure the standard Python logging module for structured logging. |
configure_structlog |
Configure structlog with the current settings. |
get_processors |
Retrieves and constructs a list of processors used for structlog logging. |
get_renderer |
Return the renderer for structlog logging based on the current environment. |
Functions¶
configure
classmethod
¶
Configure structlog and standard Python logging for structured logging.
configure_stdlib
classmethod
¶
Configure the standard Python logging module for structured logging.
configure_structlog
classmethod
¶
Configure structlog with the current settings.
get_processors
classmethod
¶
Retrieves and constructs a list of processors used for structlog logging.
This method dynamically determines the appropriate processors for the current environment and ensures they are formatted correctly for logging. In production environments, additional processors may be included based on specific requirements.
| RETURNS | DESCRIPTION |
|---|---|
list[Any]
|
A list of processor instances used for structlog logging. |
get_renderer
classmethod
¶
Return the renderer for structlog logging based on the current environment.
Production
¶
Bases: Logging[JSONRenderer]
The production logging configuration.
| METHOD | DESCRIPTION |
|---|---|
get_renderer |
Return the JSON renderer for the production environment. |
Functions¶
configure
¶
Configure structlog and standard Python logging for structured logging.
drop_color_message_key
¶
Drop the color_message key from the event dict if it exists.
Uvicorn logs the message a second time in the extra color_message, but we don't need it.
edit_event_name
¶
Edit the event dict to change the event name, so we don't clobber elastic indices.