Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log exception location #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

orivej
Copy link

@orivej orivej commented Oct 2, 2016

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

@invl
Copy link
Owner

invl commented Oct 2, 2016

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

@orivej
Copy link
Author

orivej commented Oct 2, 2016

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.

@asqui
Copy link

asqui commented Sep 20, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function name to retry log message
3 participants