Async structlog configuration

Question:

In the structlog documentation https://www.structlog.org/en/stable/performance.html is an example for a sync structlog configuration:

import logging
import structlog

structlog.configure(
    cache_logger_on_first_use=True,
    wrapper_class=structlog.make_filtering_bound_logger(logging.INFO),
    processors=[
        structlog.threadlocal.merge_threadlocal,
        structlog.processors.add_log_level,
        structlog.processors.format_exc_info,
        structlog.processors.TimeStamper(fmt="iso", utc=True),
        structlog.processors.JSONRenderer(serializer=orjson.dumps),
    ],
    logger_factory=structlog.BytesLoggerFactory(),
)

What is the equivalent async configuration?

Asked By: Henry Thornton

||

Answers:

EDIT: as of structlog 22.2.0, FilteringBoundLogger had a full set of async methods that prefix the regular ones with an a like ainfo.

It’s a different approach but I think it’s the better one and it might find its way back into stdlib.


Unfortunately, async is currently stdlib-only. The only reason is that nobody has done it yet.

The ticket to track that includes an outline of a workaround: https://github.com/hynek/structlog/issues/354~

Answered By: hynek
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.