# -*- coding:utf-8 -*-
import logging # 引入logging模块
import os.path
import time
# 第一步,创建一个logger
logger = logging.getLogger()
logger.setLevel(logging.INFO) # Log等级总开关
# 第二步,创建一个handler,用于写入日志文件
rq = time.strftime(u'%Y%m%d%H%M', time.localtime(time.time()))
log_path = u'C:/Users/feixu_yan/Desktop/Logs'
log_name = log_path + rq + u'.log'
logfile = log_name
fh = logging.FileHandler(logfile, mode=u'w')
fh.setLevel(logging.DEBUG) # 输出到file的log等级的开关
# 第三步,定义handler的输出格式
formatter = logging.Formatter(u"%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")
fh.setFormatter(formatter)
# 第四步,将logger添加到handler里面
logger.addHandler(fh)
# 日志
logger.debug(u'this is a logger debug message')
logger.info(u'this is a logger info message')
logger.warning(u'this is a logger warning message')
logger.error(u'this is a logger error message')
logger.critical(u'this is a logger critical message')