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

@@ -15,7 +15,7 @@ import warnings
from typing import Any, Callable, Iterable, Sequence, Type, cast
from ._log_levels import make_filtering_bound_logger
from ._native import make_filtering_bound_logger
from ._output import PrintLoggerFactory
from .contextvars import merge_contextvars
from .dev import ConsoleRenderer, _has_colors, set_exc_info
@@ -63,9 +63,9 @@ class _Configuration:
default_processors: Iterable[Processor] = _BUILTIN_DEFAULT_PROCESSORS[:]
default_context_class: type[Context] = _BUILTIN_DEFAULT_CONTEXT_CLASS
default_wrapper_class: Any = _BUILTIN_DEFAULT_WRAPPER_CLASS
logger_factory: Callable[
..., WrappedLogger
] = _BUILTIN_DEFAULT_LOGGER_FACTORY
logger_factory: Callable[..., WrappedLogger] = (
_BUILTIN_DEFAULT_LOGGER_FACTORY
)
cache_logger_on_first_use: bool = _BUILTIN_CACHE_LOGGER_ON_FIRST_USE
@@ -114,8 +114,7 @@ def get_logger(*args: Any, **initial_values: Any) -> Any:
>>> log.info("hello", x=42)
y=23 x=42 event='hello'
Arguments:
Args:
args:
*Optional* positional arguments that are passed unmodified to the
logger factory. Therefore it depends on the factory what they
@@ -124,7 +123,6 @@ def get_logger(*args: Any, **initial_values: Any) -> Any:
initial_values: Values that are used to pre-populate your contexts.
Returns:
A proxy that creates a correctly configured bound logger when
necessary. The type of that bound logger depends on your configuration
and is `structlog.BoundLogger` by default.
@@ -169,8 +167,7 @@ def wrap_logger(
In other words: selective overwriting of the defaults while keeping some
*is* possible.
Arguments:
Args:
initial_values: Values that are used to pre-populate your contexts.
logger_factory_args:
@@ -178,7 +175,6 @@ def wrap_logger(
the logger factory if not `None`.
Returns:
A proxy that creates a correctly configured bound logger when
necessary.
@@ -217,8 +213,7 @@ def configure(
Use `reset_defaults` to undo your changes.
Arguments:
Args:
processors: The processor chain. See :doc:`processors` for details.
wrapper_class:
@@ -269,7 +264,6 @@ def configure_once(
`configure_once` before.
Raises:
RuntimeWarning: if repeated configuration is attempted.
"""
if not _CONFIG.is_configured:
@@ -315,6 +309,11 @@ class BoundLoggerLazyProxy:
.. versionchanged:: 0.4.0 Added support for *logger_factory_args*.
"""
# fulfill BindableLogger protocol without carrying accidental state
@property
def _context(self) -> dict[str, str]:
return self._initial_values
def __init__(
self,
logger: WrappedLogger | None,
@@ -364,7 +363,9 @@ class BoundLoggerLazyProxy:
# Looks like Protocols ignore definitions of __init__ so we have to
# silence Mypy here.
logger = cls(
_logger, processors=procs, context=ctx # type: ignore[call-arg]
_logger,
processors=procs,
context=ctx, # type: ignore[call-arg]
)
def finalized_bind(**new_values: Any) -> BindableLogger: