From 51ef33f2e91bc4e07bf4084bef3dcecc97621983 Mon Sep 17 00:00:00 2001 From: evandrocoan Date: Fri, 27 Dec 2019 11:09:10 -0300 Subject: [PATCH] Add the logging.py findCaller() stacklevel as a debugger attribute because when extending the default Logger and implementing/specializing the `_log` function, all stacktraces need to be increased by 1. For example, the debug_tools pypi module inherits from Logger and defines its own _log() function: https://github.com/evandrocoan/debugtools/blob/d279bf3278f501294a72159f3aa189b7237528b2/all/debug_tools/logger.py#L166 https://github.com/evandrocoan/debugtools/blob/d279bf3278f501294a72159f3aa189b7237528b2/all/debug_tools/logger.py#L970 https://github.com/evandrocoan/debugtools/blob/d279bf3278f501294a72159f3aa189b7237528b2/all/debug_tools/logger.py#L1317 --- Lib/logging/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index ad873de08fe..adcf6bf7733 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -1403,6 +1403,7 @@ class Logger(Filterer): self.handlers = [] self.disabled = False self._cache = {} + self.default_stack_level = 2 def setLevel(self, level): """ @@ -1506,7 +1507,7 @@ class Logger(Filterer): Find the stack frame of the caller so that we can note the source file name, line number and function name. """ - f = currentframe(2 + stacklevel) + f = currentframe(self.default_stack_level + stacklevel) #On some versions of IronPython, currentframe() returns None if #IronPython isn't run with -X:Frames. if f is not None: