MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / findCaller

Method findCaller

tools/python-3.11.9-amd64/Lib/logging/__init__.py:1561–1593  ·  view source on GitHub ↗

Find the stack frame of the caller so that we can note the source file name, line number and function name.

(self, stack_info=False, stacklevel=1)

Source from the content-addressed store, hash-verified

1559 self._log(level, msg, args, **kwargs)
1560
1561 def findCaller(self, stack_info=False, stacklevel=1):
1562 """
1563 Find the stack frame of the caller so that we can note the source
1564 file name, line number and function name.
1565 """
1566 f = currentframe()
1567 #On some versions of IronPython, currentframe() returns None if
1568 #IronPython isn't run with -X:Frames.
1569 if f is None:
1570 return "(unknown file)", 0, "(unknown function)", None
1571 while stacklevel > 0:
1572 next_f = f.f_back
1573 if next_f is None:
1574 ## We've got options here.
1575 ## If we want to use the last (deepest) frame:
1576 break
1577 ## If we want to mimic the warnings module:
1578 #return ("sys", 1, "(unknown function)", None)
1579 ## If we want to be pedantic:
1580 #raise ValueError("call stack is not deep enough")
1581 f = next_f
1582 if not _is_internal_frame(f):
1583 stacklevel -= 1
1584 co = f.f_code
1585 sinfo = None
1586 if stack_info:
1587 with io.StringIO() as sio:
1588 sio.write("Stack (most recent call last):\n")
1589 traceback.print_stack(f, file=sio)
1590 sinfo = sio.getvalue()
1591 if sinfo[-1] == '\n':
1592 sinfo = sinfo[:-1]
1593 return co.co_filename, f.f_lineno, co.co_name, sinfo
1594
1595 def makeRecord(self, name, level, fn, lno, msg, args, exc_info,
1596 func=None, extra=None, sinfo=None):

Callers 1

_logMethod · 0.95

Calls 5

print_stackMethod · 0.80
currentframeFunction · 0.70
_is_internal_frameFunction · 0.70
writeMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected