retry icon indicating copy to clipboard operation
retry copied to clipboard

Log exception location

Open orivej opened this issue 9 years ago • 3 comments
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

orivej avatar Oct 02 '16 00:10 orivej

This will break python2.6 support, besides I think this could have been done by passing a custom logger, right?

invl avatar Oct 02 '16 15:10 invl

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.

orivej avatar Oct 02 '16 16:10 orivej

Just out of interest: Which part of this change breaks 2.6 compatibility?

asqui avatar Sep 20 '17 20:09 asqui