def \_\_init\_\_(self, name):
self.logger = logging.getLogger(name)
self.logger.parent.setLevel(logging.DEBUG)
self.logger.root.setLevel(logging.DEBUG)
# log存放的目录
self.log_path = os.path.join(
os.getcwd(), "log", datetime.now().strftime("%Y-%m-%d"))
# log格式化输出
self.log_formatter = logging.Formatter(
'%(asctime)s-%(levelname)s : %(message)s', '%Y-%m-%d %H:%M:%S')
# 控制台输出
self.set_console_logger()
# 文件输出日志
self.set_file_logger()
def set\_console\_logger(self):
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(self.log_formatter)
self.logger.addHandler(console_handler)
def set\_file\_logger(self):
log_message_path = os.path.join(self.log_path, "message")
log_error_path = os.path.join(self.log_path, "error")
if not os.path.exists(log_message_path):
os.
12-08
444
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-10
1046
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-01
6253
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-12
396
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交