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

Function alog

src/structlog/_native.py:215–245  ·  view source on GitHub ↗

.. versionchanged:: 23.3.0 Callsite parameters are now also collected under asyncio.

(
        self: Any, level: int, event: str, *args: Any, **kw: Any
    )

Source from the content-addressed store, hash-verified

213 )
214
215 async def alog(
216 self: Any, level: int, event: str, *args: Any, **kw: Any
217 ) -> Any:
218 """
219 .. versionchanged:: 23.3.0
220 Callsite parameters are now also collected under asyncio.
221 """
222 if level < min_level:
223 return None
224 name = LEVEL_TO_NAME[level]
225 event = _maybe_interpolate(event, args)
226
227 # Capture thread-specific info before handing off to the executor.
228 thread_token = _ASYNC_CALLING_THREAD.set(
229 (threading.get_ident(), threading.current_thread().name)
230 )
231 scs_token = _ASYNC_CALLING_STACK.set(sys._getframe().f_back) # type: ignore[arg-type]
232 ctx = contextvars.copy_context()
233
234 try:
235 runner = await asyncio.get_running_loop().run_in_executor(
236 None,
237 lambda: ctx.run(
238 lambda: self._proxy_to_logger(name, event, **kw)
239 ),
240 )
241 finally:
242 _ASYNC_CALLING_STACK.reset(scs_token)
243 _ASYNC_CALLING_THREAD.reset(thread_token)
244
245 return runner
246
247 meths: dict[str, Callable[..., Any]] = {"log": log, "alog": alog}
248 for lvl, name in LEVEL_TO_NAME.items():

Callers

nothing calls this directly

Calls 3

_maybe_interpolateFunction · 0.85
runMethod · 0.45
_proxy_to_loggerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…