删除 logger 模块注释

This commit is contained in:
洛水.山岭居室 2022-05-24 20:15:17 +08:00
parent f25e9dc7b4
commit 7c48eb842d

View File

@ -1,13 +1,13 @@
import logging
from logging.handlers import RotatingFileHandler # 按文件大小滚动备份
import colorlog # 控制台日志输入颜色
from logging.handlers import RotatingFileHandler
import colorlog
import os
current_path = os.path.realpath(os.getcwd()) # log_path是存放日志的路径
current_path = os.path.realpath(os.getcwd())
log_path = os.path.join(current_path, 'logs')
if not os.path.exists(log_path):
os.mkdir(log_path) # 如果不存在这个logs文件夹就自动创建一个
log_file_name = os.path.join(log_path, 'log.log') # 文件的命名
os.mkdir(log_path)
log_file_name = os.path.join(log_path, 'log.log')
log_colors_config = {
'DEBUG': 'cyan',
@ -31,9 +31,8 @@ class Logger:
return self.logger
def _console(self, level, message, exc_info=None):
# 创建一个FileHandler用于写到本地
fh = RotatingFileHandler(filename=log_file_name, maxBytes=1024 * 1024 * 5, backupCount=5,
encoding='utf-8') # 使用RotatingFileHandler类滚动备份日志
encoding='utf-8')
fh.setLevel(logging.INFO)
fh.setFormatter(self.formatter2)
self.logger.addHandler(fh)
@ -51,11 +50,10 @@ class Logger:
self.logger.warning(msg=message, exc_info=exc_info)
elif level == 'error':
self.logger.error(msg=message, exc_info=exc_info)
# 这两行代码是为了避免日志输出重复问题
self.logger.removeHandler(ch)
self.logger.removeHandler(fh)
fh.close() # 关闭打开的文件
ch.close()
fh.close()
def debug(self, msg, exc_info=None):
self._console('debug', msg, exc_info)