0

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?

Henry Thornton
  • 4,381
  • 9
  • 36
  • 43
  • Please note my updated answer: structlog now has async methods for nkn-stdlib. No config necessary. – hynek Feb 17 '23 at 05:45

1 Answers1

2

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~

hynek
  • 3,647
  • 1
  • 18
  • 26