From 414475db1a4982142fdd4e5327602b0dd43e0ba8 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Wed, 20 Jul 2022 11:06:31 +0200 Subject: [PATCH] Add structlog.contextvars.merge_contextvars to default config --- CHANGELOG.md | 2 ++ docs/getting-started.rst | 1 + pyproject.toml | 2 +- src/structlog/_config.py | 2 ++ src/structlog/stdlib.py | 5 +++-- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8faa4433..f4b2b4d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,8 @@ So please make sure to **always** properly configure your applications. - `structlog.processors.format_exc_info()` is no longer a function, but an instance of `structlog.processors.ExceptionRenderer`. Its behavior has not changed. [#407](https://github.com/hynek/structlog/pull/407) +- The default configuration now includes the `structlog.contextvars.merge_contextvars` processor. + That means you can use [`structlog.contextvars`](https://www.structlog.org/en/stable/contextvars.html) features without configuring `structlog`. ### Fixed diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 7fe65b89..7698888d 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -48,6 +48,7 @@ Using the defaults, as above, is equivalent to:: structlog.configure( processors=[ + structlog.contextvars.merge_contextvars, structlog.processors.add_log_level, structlog.processors.StackInfoRenderer(), structlog.dev.set_exc_info, diff --git a/pyproject.toml b/pyproject.toml index 6c52ddf5..f51e6bd8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -226,7 +226,7 @@ If you prefer videos over reading, check out `Markus Holtermann `_ and `MIT `_ +- **License**: *dual* `Apache License, version 2 and MIT `_ - **PyPI**: https://pypi.org/project/structlog/ - **Source Code**: https://github.com/hynek/structlog - **Documentation**: https://www.structlog.org/ diff --git a/src/structlog/_config.py b/src/structlog/_config.py index c069dfdd..e878c3e2 100644 --- a/src/structlog/_config.py +++ b/src/structlog/_config.py @@ -24,6 +24,7 @@ from ._log_levels import make_filtering_bound_logger from ._loggers import PrintLoggerFactory +from .contextvars import merge_contextvars from .dev import ConsoleRenderer, _use_colors, set_exc_info from .processors import StackInfoRenderer, TimeStamper, add_log_level from .types import BindableLogger, Context, Processor, WrappedLogger @@ -36,6 +37,7 @@ - structlog.stdlib.recreate_defaults()'s docstring. """ _BUILTIN_DEFAULT_PROCESSORS: Sequence[Processor] = [ + merge_contextvars, add_log_level, StackInfoRenderer(), set_exc_info, diff --git a/src/structlog/stdlib.py b/src/structlog/stdlib.py index 0496b244..208b1372 100644 --- a/src/structlog/stdlib.py +++ b/src/structlog/stdlib.py @@ -20,13 +20,13 @@ from functools import partial from typing import Any, Callable, Collection, Iterable, Sequence -from structlog.processors import StackInfoRenderer - from . import _config from ._base import BoundLoggerBase from ._frames import _find_first_app_frame_and_name, _format_stack from ._log_levels import _LEVEL_TO_NAME, _NAME_TO_LEVEL, add_log_level +from .contextvars import merge_contextvars from .exceptions import DropEvent +from .processors import StackInfoRenderer from .types import Context, EventDict, ExcInfo, Processor, WrappedLogger @@ -83,6 +83,7 @@ def recreate_defaults(*, log_level: int | None = logging.NOTSET) -> None: _config.reset_defaults() _config.configure( processors=[ + merge_contextvars, add_log_level, StackInfoRenderer(), _config._BUILTIN_DEFAULT_PROCESSORS[-2], # TimeStamper