This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user