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

Function tmp_bind

src/structlog/threadlocal.py:139–159  ·  view source on GitHub ↗

Bind *tmp_values* to *logger* & memorize current state. Rewind afterwards. Only works with `structlog.threadlocal.wrap_dict`-based contexts. Use :func:`~structlog.threadlocal.bound_threadlocal` for new code. .. deprecated:: 22.1.0

(
    logger: TLLogger, **tmp_values: Any
)

Source from the content-addressed store, hash-verified

137
138@contextlib.contextmanager
139def tmp_bind(
140 logger: TLLogger, **tmp_values: Any
141) -> Generator[TLLogger, None, None]:
142 """
143 Bind *tmp_values* to *logger* & memorize current state. Rewind afterwards.
144
145 Only works with `structlog.threadlocal.wrap_dict`-based contexts.
146 Use :func:`~structlog.threadlocal.bound_threadlocal` for new code.
147
148 .. deprecated:: 22.1.0
149 """
150 _deprecated()
151 if isinstance(logger, BoundLoggerLazyProxy):
152 logger = logger.bind()
153
154 saved = as_immutable(logger)._context
155 try:
156 yield logger.bind(**tmp_values)
157 finally:
158 logger._context.clear()
159 logger._context.update(saved)
160
161
162class _ThreadLocalDictWrapper:

Callers 3

test_bindMethod · 0.90
test_bind_excMethod · 0.90
test_tmp_bind_lazyMethod · 0.90

Calls 4

_deprecatedFunction · 0.85
as_immutableFunction · 0.85
updateMethod · 0.80
bindMethod · 0.45

Tested by 3

test_bindMethod · 0.72
test_bind_excMethod · 0.72
test_tmp_bind_lazyMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…