retry
retry copied to clipboard
Log exception location
trafficstars
This prefixes an exception message with file name and line number of the function invoked by retry that caused the exception; WARNING exception becomes WARNING x.py:13: exception.
Fixes #9
This will break python2.6 support, besides I think this could have been done by passing a custom logger, right?
A custom logger like this works:
import os
import sys
import traceback
from retry.api import logging_logger
class location_logger(object):
@staticmethod
def warning(fmt, error, delay):
path, line, func, src = traceback.extract_tb(sys.exc_info()[2], 2)[1]
shortpath = os.path.join(os.path.basename(os.path.dirname(path)),
os.path.basename(path))
logging_logger.warning('%s:%s: %s, retrying in %s seconds...',
shortpath, line, error, delay)
Feel free to discard this pull request, as built in support for location logging would be nice, but I am not sure about the right API.
Just out of interest: Which part of this change breaks 2.6 compatibility?