Wraps a `BoundLogger` & exposes its logging methods as ``async`` versions. This approach has turned out to be a mistake and the class has been deprecated in 23.1.0. Use the regular `BoundLogger` with its a-prefixed methods instead. .. versionadded:: 20.2.0 .. versionchange
| 559 | |
| 560 | |
| 561 | class AsyncBoundLogger: |
| 562 | """ |
| 563 | Wraps a `BoundLogger` & exposes its logging methods as ``async`` versions. |
| 564 | |
| 565 | This approach has turned out to be a mistake and the class has been |
| 566 | deprecated in 23.1.0. Use the regular `BoundLogger` with its a-prefixed |
| 567 | methods instead. |
| 568 | |
| 569 | .. versionadded:: 20.2.0 |
| 570 | .. versionchanged:: 20.2.0 fix _dispatch_to_sync contextvars usage |
| 571 | .. deprecated:: 23.1.0 |
| 572 | Use the regular `BoundLogger` with its a-prefixed methods instead. |
| 573 | .. versionchanged:: 23.3.0 |
| 574 | Callsite parameters are now also collected for async log methods. |
| 575 | """ |
| 576 | |
| 577 | __slots__ = ("_loop", "sync_bl") |
| 578 | |
| 579 | #: The wrapped synchronous logger. It is useful to be able to log |
| 580 | #: synchronously occasionally. |
| 581 | sync_bl: BoundLogger |
| 582 | |
| 583 | _executor = None |
| 584 | _bound_logger_factory = BoundLogger |
| 585 | |
| 586 | def __init__( |
| 587 | self, |
| 588 | logger: logging.Logger, |
| 589 | processors: Iterable[Processor], |
| 590 | context: Context, |
| 591 | *, |
| 592 | # Only as an optimization for binding! |
| 593 | _sync_bl: Any = None, # *vroom vroom* over purity. |
| 594 | _loop: Any = None, |
| 595 | ): |
| 596 | if _sync_bl: |
| 597 | self.sync_bl = _sync_bl |
| 598 | self._loop = _loop |
| 599 | |
| 600 | return |
| 601 | |
| 602 | self.sync_bl = self._bound_logger_factory( |
| 603 | logger=logger, processors=processors, context=context |
| 604 | ) |
| 605 | self._loop = asyncio.get_running_loop() |
| 606 | |
| 607 | # Instances would've been correctly recognized as such, however the class |
| 608 | # not and we need the class in `structlog.configure()`. |
| 609 | @property |
| 610 | def _context(self) -> Context: |
| 611 | return self.sync_bl._context |
| 612 | |
| 613 | def bind(self, **new_values: Any) -> Self: |
| 614 | return self.__class__( |
| 615 | # logger, processors and context are within sync_bl. These |
| 616 | # arguments are ignored if _sync_bl is passed. *vroom vroom* over |
| 617 | # purity. |
| 618 | logger=None, # type: ignore[arg-type] |
no outgoing calls
searching dependent graphs…