Skip to content

Commit

Permalink
Add structlog.contextvars.merge_contextvars to default config
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Jul 20, 2022
1 parent d366240 commit 414475d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ If you prefer videos over reading, check out `Markus Holtermann <https://twitter
Project Information
===================
- **License**: dual-licensed under `Apache License, version 2 <https://choosealicense.com/licenses/apache/>`_ and `MIT <https://choosealicense.com/licenses/mit/>`_
- **License**: *dual* `Apache License, version 2 and MIT <https://www.structlog.org/en/stable/license.html>`_
- **PyPI**: https://pypi.org/project/structlog/
- **Source Code**: https://github.com/hynek/structlog
- **Documentation**: https://www.structlog.org/
Expand Down
2 changes: 2 additions & 0 deletions src/structlog/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +37,7 @@
- structlog.stdlib.recreate_defaults()'s docstring.
"""
_BUILTIN_DEFAULT_PROCESSORS: Sequence[Processor] = [
merge_contextvars,
add_log_level,
StackInfoRenderer(),
set_exc_info,
Expand Down
5 changes: 3 additions & 2 deletions src/structlog/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 414475d

Please sign in to comment.