因此,在阅读文档和几个 stackoverflow 问题并在 Python 3.4 中尝试之后,我不明白。它什么时候旋转,在什么条件下旋转?
有2个线程,它们永远不会停止。他们称此代码为(我知道 logger 已经是单例,实用程序中有更多不相关的代码):
import logging
from singleton import Singleton
from logging.handlers import TimedRotatingFileHandler
class Utility(metaclass=Singleton):
def _logger(self):
logger = logging.getLogger("main")
logger.setLevel(logging.INFO)
if not logger.hasHandlers():
handler = TimedRotatingFileHandler(
filename = "info.log",
when = 's',
interval = 10,
backupCount = 10,
encoding = 'utf-8'
)
logger.addHandler(handler)
return logger
def log(self, *text):
self._logger().info(' '.join(str(t) for t in text))