log日志模块得作用

import logging
logger=logging.getLogger()
logger.setLevel(logging.DEBUG)
#控制台输出日志
'''consle=logging.StreamHandler()
logger.addHandler(consle)'''
#文件输出日志
# file_handle=logging.FileHandler(r"F:\QQ\log\test.log")
# formatter=logging.Formatter('%(asctime)s %(filename)s---> %(funcName)s %(levelno)s %(levelname)s --->%(message)s')
# file_handle.setFormatter(formatter)
# logger.addHandler(file_handle)

file_handle=logging.FileHandler(r"F:\QQ\log\test.log")
formatter=logging.Formatter("%(asctime)s %(filename)s ----> %(funcName)s %(levelno)s %(levelname)s -->%(message)s")
file_handle.setFormatter(formatter)
logger.addHandler(file_handle)

logger.debug("test666")
print("test885")
file_handle.close()
logger.removeHandler(file_handle)
posted @ 2018-12-04 14:13  taotao12  阅读(405)  评论(0编辑  收藏  举报