Python日志记录:自动日志旋转未正确发生
我在python中编写了一个名为logger的Python日志记录:自动日志旋转未正确发生,python,logging,Python,Logging,我在python中编写了一个名为logger的Singleton模块,它使用python的logging模块。My App.py使用记录器模块处理日志 我在2014年11月3日运行App.py,创建了logger.log(A) 我在2014年11月4日运行App.py,创建了logger.logA更名为logger.log.2014-11-03。因此,原木旋转发生了。那很好 但从11月5日开始,当App.py由supervisord在我的生产系统上连续运行时,我得到了以下结果 (11月5日)lo
Singleton
模块,它使用python的logging
模块。My App.py使用记录器模块处理日志
supervisord
在我的生产系统上连续运行时,我得到了以下结果
(11月5日)logger.log有2014-05-01的日志(11月6日)logger.log(大小=3.6M+)包含2014-06-01的日志
(11月6日)logger.log.2014-11-05(尺寸=76米),包含2014-06-01的日志
import logging.config
import sys
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class Logger(object):
__metaclass__ = Singleton
def __init__(self, *args, **kwds):
print "Logger Init Starts"
self.configFile = None
if args:
self.configFile = args[0]
else:
sys.exit("ERROR! Config file not passed to Logger class")
logging.config.fileConfig(self.configFile)
self.logger = logging.getLogger('Logger')
self.logger.info('log handler initilizes')
print "Logger Init Ends"
def debug(self, msg):
self.logger.debug(msg)
def info(self, msg):
self.logger.info(msg)
def warn(self, msg):
self.logger.warn(msg)
def error(self, msg):
self.logger.error(msg)
def critical(self, msg):
self.logger.critical(msg)
if __name__ == "__main__":
log = Logger()
我在我的App.py
模块中使用上述记录器模块
# ... some imports
import logger
class App:
def __init__(self, configFile=None):
self.configFile = configFile;
self.log = logger.Logger(self.configFile)
self.log.info('constructor of App')
# ... more code
我的配置文件如下所示
[loggers]
keys=root
[handlers]
keys=file,screen
[formatters]
keys=simple,complex
[logger_root]
level=DEBUG
handlers=screen,file
[handler_file]
class=handlers.TimedRotatingFileHandler
interval=1
backupCount=0
formatter=complex
level=DEBUG
args=('../../logs/logger.log','midnight',1,0)
[handler_screen]
class=StreamHandler
formatter=simple
level=DEBUG
args=(sys.stdout,)
[formatter_simple]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
[formatter_complex]
format=%(asctime)s - %(name)s - %(levelname)s - %(module)s : %(lineno)d - %(message)s
为什么日志旋转不正常?请帮帮我。谢谢