python装饰器类

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

 

posted @ 2019-07-15 16:20  1553  阅读(702)  评论(0编辑  收藏  举报