Skip to content

Instantly share code, notes, and snippets.

@SaitTalhaNisanci
Created April 10, 2019 21:46
Show Gist options
  • Save SaitTalhaNisanci/3d0de6369df3787360705cca6c49bac3 to your computer and use it in GitHub Desktop.
Save SaitTalhaNisanci/3d0de6369df3787360705cca6c49bac3 to your computer and use it in GitHub Desktop.
def log_on_exception(*tags):
"""
A utility decorator to log the exception with
the given tags.
it reraises the exception.
"""
def decorator(function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
try:
return function(*args, **kwargs)
except:
log_message = 'There was an exception in '
log_message += function.__name__
# log the exception
log(log_message, tags)
# re-raise the exception
raise
return wrapper
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment