# 装饰器
import logging
# def user_logging(func):
# def wrapper(*args, **kwargs):
# logging.warning('%s is running' % func.__name__)
# return func(*args, **kwargs)
# return wrapper
#
#
# def bar():
# print('i am bar')
#
#
# bar = user_logging(bar)
# bar()
def user_logging(level):
def decorator(func):
def wrapper(*args, **kwargs):
if level == 'warn':
logging.warning('%s is running' % func.__name__)
return func(*args, **kwargs)
return wrapper
return decorator
@user_logging(level='warn')
def bar(name='bar'):
print('i am bar %s' % name)
bar()