MCPcopy Create free account
hub / github.com/hynek/structlog / recreate_defaults

Function recreate_defaults

src/structlog/stdlib.py:71–117  ·  view source on GitHub ↗

Recreate defaults on top of standard library's logging. The output looks the same, but goes through `logging`. As with vanilla defaults, the backwards-compatibility guarantees don't apply to the settings applied here. Args: log_level: If `None`, don't conf

(*, log_level: int | None = logging.NOTSET)

Source from the content-addressed store, hash-verified

69
70
71def recreate_defaults(*, log_level: int | None = logging.NOTSET) -> None:
72 """
73 Recreate defaults on top of standard library's logging.
74
75 The output looks the same, but goes through `logging`.
76
77 As with vanilla defaults, the backwards-compatibility guarantees don't
78 apply to the settings applied here.
79
80 Args:
81 log_level:
82 If `None`, don't configure standard library logging **at all**.
83
84 Otherwise configure it to log to `sys.stdout` at *log_level*
85 (``logging.NOTSET`` being the default).
86
87 If you need more control over `logging`, pass `None` here and
88 configure it yourself.
89
90 .. versionadded:: 22.1.0
91 .. versionchanged:: 23.3.0 Added `add_logger_name`.
92 .. versionchanged:: 25.1.0 Added `PositionalArgumentsFormatter`.
93 """
94 if log_level is not None:
95 kw = {"force": True}
96
97 logging.basicConfig(
98 format="%(message)s",
99 stream=sys.stdout,
100 level=log_level,
101 **kw, # type: ignore[call-overload]
102 )
103
104 _config.reset_defaults()
105 _config.configure(
106 processors=[
107 PositionalArgumentsFormatter(), # handled by native loggers
108 merge_contextvars,
109 add_log_level,
110 add_logger_name,
111 StackInfoRenderer(),
112 _config._BUILTIN_DEFAULT_PROCESSORS[-2], # TimeStamper
113 _config._BUILTIN_DEFAULT_PROCESSORS[-1], # ConsoleRenderer
114 ],
115 wrapper_class=BoundLogger,
116 logger_factory=LoggerFactory(),
117 )
118
119
120_SENTINEL = object()

Callers 1

test_recreate_defaultsFunction · 0.90

Calls 3

StackInfoRendererClass · 0.85
LoggerFactoryClass · 0.70

Tested by 1

test_recreate_defaultsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…