API refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-07 16:25:52 +09:00
parent 76d0d86211
commit 91c7e04474
1171 changed files with 81940 additions and 44117 deletions

View File

@@ -17,6 +17,7 @@ from contextlib import contextmanager
from typing import Any, Generator, NamedTuple, NoReturn
from ._config import configure, get_config
from ._log_levels import map_method_name
from .exceptions import DropEvent
from .typing import EventDict, WrappedLogger
@@ -41,6 +42,10 @@ class LogCapture:
:ivar List[structlog.typing.EventDict] entries: The captured log entries.
.. versionadded:: 20.1.0
.. versionchanged:: 24.3.0
Added mapping from "exception" to "error"
Added mapping from "warn" to "warning"
"""
entries: list[EventDict]
@@ -51,7 +56,7 @@ class LogCapture:
def __call__(
self, _: WrappedLogger, method_name: str, event_dict: EventDict
) -> NoReturn:
event_dict["log_level"] = method_name
event_dict["log_level"] = map_method_name(method_name)
self.entries.append(event_dict)
raise DropEvent
@@ -139,8 +144,7 @@ class CapturedCall(NamedTuple):
Can also be unpacked like a tuple.
Arguments:
Args:
method_name: The method name that got called.
args: A tuple of the positional arguments.
@@ -173,7 +177,7 @@ class CapturingLogger:
self.calls = []
def __repr__(self) -> str:
return f"<CapturingLogger with { len(self.calls) } call(s)>"
return f"<CapturingLogger with {len(self.calls)} call(s)>"
def __getattr__(self, name: str) -> Any:
"""
@@ -190,7 +194,7 @@ class CapturingLoggerFactory:
r"""
Produce and cache `CapturingLogger`\ s.
Each factory produces and re-uses only **one** logger.
Each factory produces and reuses only **one** logger.
You can access it via the ``logger`` attribute.
@@ -200,6 +204,7 @@ class CapturingLoggerFactory:
.. versionadded:: 20.2.0
"""
logger: CapturingLogger
def __init__(self) -> None: