tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Allow stack_info argument in before_sleep_log strategy

Open jpark712 opened this issue 4 years ago • 0 comments

#227 adds the exc_info parameter to the before_sleep_log() function. This is nice, but the stack trace ends at the place where the exception is raised. It may be useful to have the entire stack context as part of the log by allowing the stack_info argument to the logger.

See description in the logging documentation:

The second optional keyword argument is stack_info, which defaults to False. If true, stack information is added to the logging message, including the actual logging call. Note that this is not the same stack information as that displayed through specifying exc_info: The former is stack frames from the bottom of the stack up to the logging call in the current thread, whereas the latter is information about stack frames which have been unwound, following an exception, while searching for exception handlers.

You can specify stack_info independently of exc_info, e.g. to just show how you got to a certain point in your code, even when no exceptions were raised. The stack frames are printed following a header line which says:

Stack (most recent call last):

This mimics the Traceback (most recent call last): which is used when displaying exception frames.

Note, I have this coded up. Just let me know if this is okay and I can open a PR.

jpark712 avatar Apr 14 '21 05:04 jpark712