Before sleep log stack info
This change adds the stack_info parameter to the before_sleep_log() function and passes it to the logger function. When set to True, logger will include a stack dump at the current location, which can be useful to pinpointing the exact location in code that triggered a retry.
Closes #290
Example of before_sleep_log called with exc_info=True, stack_info=False:
test_func called()
INFO:__main__:Retrying __main__.test_func in 1.0 seconds as it raised Exception: my error.
Traceback (most recent call last):
File "C:\github\forks\tenacity\tenacity\__init__.py", line 433, in __call__
result = fn(*args, **kwargs)
File ".\ten.py", line 35, in test_func
raise Exception("my error")
Exception: my error
Example of before_sleep_log called with exc_info=True, stack_info=True. Notice we can now see that test_func was called from line 117 from the main() method whereas before, we only get the line that raised the exception.
test_func called()
INFO:__main__:Retrying __main__.test_func in 1.0 seconds as it raised Exception: my error.
Traceback (most recent call last):
File "C:\github\forks\tenacity\tenacity\__init__.py", line 433, in __call__
result = fn(*args, **kwargs)
File ".\ten.py", line 35, in test_func
raise Exception("my error")
Exception: my error
Stack (most recent call last):
File ".\ten.py", line 117, in <module>
main()
File ".\ten.py", line 94, in main
r.call(test_func, 1, 2)
File "C:\github\forks\tenacity\tenacity\__init__.py", line 419, in call
return self.__call__(*args, **kwargs)
File "C:\github\forks\tenacity\tenacity\__init__.py", line 430, in __call__
do = self.iter(retry_state=retry_state)
File "C:\github\forks\tenacity\tenacity\__init__.py", line 391, in iter
self.before_sleep(retry_state=retry_state)
File "C:\github\forks\tenacity\tenacity\before_sleep.py", line 41, in log_it
logger.log(
Ah I think CI is broken again. Really need to move to GH Actions.
This would be super useful to have. Is there any chance of landing this soon?
Old and in conflict, closing.