mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-04 01:21:03 +03:00
Simply walk up the stack finding the frame we want.
Also leave that 'A.B' test around as a hint for a unittest. Obviously that instantiation will need commenting out for a release.
This commit is contained in:
parent
5a779a3379
commit
2eba647f17
@ -92,35 +92,26 @@ class EDMCContextFilter(logging.Filter):
|
|||||||
|
|
||||||
:return: Tuple[str, str]: The caller's class name and qualname
|
:return: Tuple[str, str]: The caller's class name and qualname
|
||||||
"""
|
"""
|
||||||
# TODO: we might as well just walk this below.
|
|
||||||
# Build the stack of frames from here upwards
|
|
||||||
stack = []
|
|
||||||
frame = sys._getframe(0)
|
|
||||||
while frame:
|
|
||||||
stack.append(frame)
|
|
||||||
frame = frame.f_back
|
|
||||||
|
|
||||||
# Go up through stack frames until we find the first with a
|
# Go up through stack frames until we find the first with a
|
||||||
# type(f_locals.self) of logging.Logger. This should be the start
|
# type(f_locals.self) of logging.Logger. This should be the start
|
||||||
# of the frames internal to logging.
|
# of the frames internal to logging.
|
||||||
f = 0
|
frame = sys._getframe(0)
|
||||||
while stack[f]:
|
while frame:
|
||||||
if type(stack[f].f_locals.get('self')) == logging.Logger:
|
if type(frame.f_locals.get('self')) == logging.Logger:
|
||||||
f += 1 # Want to start on the next frame below
|
frame = frame.f_back # Want to start on the next frame below
|
||||||
break
|
break
|
||||||
f += 1
|
frame = frame.f_back
|
||||||
|
|
||||||
# Now continue up through frames until we find the next one where
|
# Now continue up through frames until we find the next one where
|
||||||
# that is *not* true, as it should be the call site of the logger
|
# that is *not* true, as it should be the call site of the logger
|
||||||
# call
|
# call
|
||||||
while stack[f]:
|
while frame:
|
||||||
if type(stack[f].f_locals.get('self')) != logging.Logger:
|
if type(frame.f_locals.get('self')) != logging.Logger:
|
||||||
break # We've found the frame we want
|
break # We've found the frame we want
|
||||||
f += 1
|
frame = frame.f_back
|
||||||
|
|
||||||
caller_qualname = caller_class_name = ''
|
caller_qualname = caller_class_name = ''
|
||||||
if stack[f]:
|
if frame:
|
||||||
frame = stack[f]
|
|
||||||
if frame.f_locals and 'self' in frame.f_locals:
|
if frame.f_locals and 'self' in frame.f_locals:
|
||||||
|
|
||||||
# Find __qualname__ of the caller
|
# Find __qualname__ of the caller
|
||||||
|
Loading…
x
Reference in New Issue
Block a user