1 import logging 2 3 def use_logging(func): 4 def writelog(*args, **kwargs): 5 logging.warning("%s is running xxx" % func.__name__) 6 return func(*args) 7 8 return writelog 9 10 def far(): 11 print("far....") 12 13 @use_logging 14 def bar(): 15 print("装饰器") 16 17 if __name__ == '__main__': 18 19 far = use_logging(far) 20 far() 21 bar()