import logging
import logging.handlers
import os
import time
class Log():
def log(self):
# 创建logger对象
logger=logging.getLogger()
# 设置日志水平
logger.setLevel(logging.DEBUG)
# 设置处理器
path = os.path.abspath('.')+'/'+ time.strftime('%Y-%m-%d-%H-%M-%S') + '.log'
write_file=logging.FileHandler(path,'a+',encoding='utf-8')
# 添加格式
write_file.setFormatter(logging.Formatter("%(asctime)s)-%(levelname)s-%(filename)s[:%(lineno)d]-%(message)s"))
# 为该logger对象添加 一个handler对象
logger.addHandler(write_file)
return logger
06-08
315
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交