Python---进阶---logging---装饰器打印日志2
2020-12-13 03:00
标签:不同的 python ctime erro bug conf func int file ### logging - logging.debug - logging.info - logging.warning - logging.error - logging.critical -------------------------------- Python---进阶---logging---装饰器打印日志2 标签:不同的 python ctime erro bug conf func int file 原文地址:https://www.cnblogs.com/niaocaizhou/p/11063707.html
logging.info("this is info")
logging.warning("this is warning")
logging.error("this is error")
logging.critical("this is critical")
- 使用装饰器,打印函数执行的时间
logging.basicConfig(format = LOG_FORMART)
def wrapper(*arg, **kw):
logging.error("this is info message")
return func(*arg, **kw)
return wrapper
@log
def test():
print("test done")
test()
logging.basicConfig(format = LOG_FORMART, filename = "my.log")
def log(text):
def decorator(func):
def wrapper(*arg, **kw):
logging.error(text)
return func(*arg, **kw)
return wrapper
return decorator
def test():
print("test done")
@log("main log")
def main():
print("main done")
main()
上一篇:java--ArrayList
下一篇:Python sorted 函数
文章标题:Python---进阶---logging---装饰器打印日志2
文章链接:http://soscw.com/essay/26749.html