from functools import wraps class logit(object): def __init__(self, logger): self.logger = logger def __call__(self, func): @wraps(func) def wrapped_function(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: self.logger.error(func.__name__ + 'error message') self.notify() return false return wrapped_function def notify(self): pass @logit(logger) def myfun(): pass