所有应用程序模块共享的简单日志服务
logging-singleton的Python项目详细描述
单例日志服务
保证是单例的日志服务。基于Python的日志, 但是LoggingService的每个实例化都来自于应用程序的任何模块 返回相同的记录器实例。默认情况下使用RotatingFileHandler。在
代码示例:
from logging_service import LoggingService
self.log = LoggingService()
self.log.info("Constructing output file names...")
self.log.err("Failed to construct output file names...")
self.log.warn("Output file names are unusual...")
self.log.debug("Constructing output file names foo.bar, fum.txt...")
如果另一个模块按照上面的方法导入并实例化LoggingService(), 将使用相同的记录器实例。在
这个API比分层的本地日志模块更原始, 但希望使用简单。可以登录到文件或控制台。 为info/debug/warn/err内置了一个格式化程序。示例:
my_module.py(290375): 2020-09-03 14:58:33,017;INFO: Start Epoch [1/50]
当第一次创建LoggingService实例时,以下选项 在构造函数中可用;所有选项都是可选的:
^{pr2}$创建后,只能按如下方式修改记录器实例:
- my_logger.logging_level = logging.NEW_LEVEL
- my_logger.log_file = '/tmp/new_logfile'
其中日志记录级别是通常的logging.INFO,
logging.WARN
,等等
- 项目
标签: