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)
| 1593 | self._log(level, msg, args, **kwargs) |
| 1594 | |
| 1595 | def findCaller(self, stack_info=False, stacklevel=1): |
| 1596 | """ |
| 1597 | Find the stack frame of the caller so that we can note the source |
| 1598 | file name, line number and function name. |
| 1599 | """ |
| 1600 | f = currentframe() |
| 1601 | #On some versions of IronPython, currentframe() returns None if |
| 1602 | #IronPython isn't run with -X:Frames. |
| 1603 | if f is None: |
| 1604 | return "(unknown file)", 0, "(unknown function)", None |
| 1605 | while stacklevel > 0: |
| 1606 | next_f = f.f_back |
| 1607 | if next_f is None: |
| 1608 | ## We've got options here. |
| 1609 | ## If we want to use the last (deepest) frame: |
| 1610 | break |
| 1611 | ## If we want to mimic the warnings module: |
| 1612 | #return ("sys", 1, "(unknown function)", None) |
| 1613 | ## If we want to be pedantic: |
| 1614 | #raise ValueError("call stack is not deep enough") |
| 1615 | f = next_f |
| 1616 | if not _is_internal_frame(f): |
| 1617 | stacklevel -= 1 |
| 1618 | co = f.f_code |
| 1619 | sinfo = None |
| 1620 | if stack_info: |
| 1621 | with io.StringIO() as sio: |
| 1622 | sio.write("Stack (most recent call last):\n") |
| 1623 | traceback.print_stack(f, file=sio) |
| 1624 | sinfo = sio.getvalue() |
| 1625 | if sinfo[-1] == '\n': |
| 1626 | sinfo = sinfo[:-1] |
| 1627 | return co.co_filename, f.f_lineno, co.co_name, sinfo |
| 1628 | |
| 1629 | def makeRecord(self, name, level, fn, lno, msg, args, exc_info, |
| 1630 | func=None, extra=None, sinfo=None): |