我是日志记录和 python 的新手,并且找到了一个logbook
我想使用的库。我正在尝试某种intiliaze
日志文件的包装器,然后我可以从不同的文件中调用它。
但我一直低于错误。我究竟做错了什么?
self.stream = io.open(self._filename, mode, encoding=self.encoding)
TypeError: expected str, bytes or os.PathLike object, not NoneType
记录器.py
from logbook import Logger, StreamHandler
from logbook import FileHandler
import sys
import os
log = Logger()
initialized = False
def make_log_dir_if_missing(log_dir):
import cheetax.utils.system
cheetax.system.make_directory(log_dir)
def initialize_logger(path=None):
global initialized, log
if initialized:
return
if path is not None:
make_log_dir_if_missing(path)
log_path = os.path.join(path, 'logger.log')
log_handler = FileHandler(path)
log_handler.push_application()
initialized = True
GLOBAL_LOGGER = log
剪辑.py
def main():
initialize_logger()
其它文件
logger.info(welcome)