This commit is contained in:
@@ -10,9 +10,7 @@ import traceback
|
||||
|
||||
from io import StringIO
|
||||
from types import FrameType
|
||||
from typing import Callable
|
||||
|
||||
from .contextvars import _ASYNC_CALLING_STACK
|
||||
from .typing import ExcInfo
|
||||
|
||||
|
||||
@@ -22,6 +20,9 @@ def _format_exception(exc_info: ExcInfo) -> str:
|
||||
|
||||
Shamelessly stolen from stdlib's logging module.
|
||||
"""
|
||||
if exc_info == (None, None, None): # type: ignore[comparison-overlap]
|
||||
return "MISSING"
|
||||
|
||||
sio = StringIO()
|
||||
|
||||
traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], None, sio)
|
||||
@@ -35,27 +36,23 @@ def _format_exception(exc_info: ExcInfo) -> str:
|
||||
|
||||
def _find_first_app_frame_and_name(
|
||||
additional_ignores: list[str] | None = None,
|
||||
*,
|
||||
_getframe: Callable[[], FrameType] = sys._getframe,
|
||||
) -> tuple[FrameType, str]:
|
||||
"""
|
||||
Remove all intra-structlog calls and return the relevant app frame.
|
||||
|
||||
Args:
|
||||
Arguments:
|
||||
|
||||
additional_ignores:
|
||||
Additional names with which the first frame must not start.
|
||||
|
||||
_getframe:
|
||||
Callable to find current frame. Only for testing to avoid
|
||||
monkeypatching of sys._getframe.
|
||||
|
||||
Returns:
|
||||
|
||||
tuple of (frame, name)
|
||||
"""
|
||||
ignores = tuple(["structlog"] + (additional_ignores or []))
|
||||
f = _ASYNC_CALLING_STACK.get(_getframe())
|
||||
ignores = ["structlog"] + (additional_ignores or [])
|
||||
f = sys._getframe()
|
||||
name = f.f_globals.get("__name__") or "?"
|
||||
while name.startswith(ignores):
|
||||
while any(tuple(name.startswith(i) for i in ignores)):
|
||||
if f.f_back is None:
|
||||
name = "?"
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user