Python logging : Automatic log rotation is not happening properly -
i have written singleton
module called logger in python uses python's logging
module. app.py uses logger module handling logs.
i ran app.py on 3 nov 2014 , logger.log (a) created.
i ran app.py on 4 nov 2014 , logger.log created. a renamed logger.log.2014-11-03. log rotation happend. that's fine.
but when app.py run supervisord
continuously on production scheme starting 5 nov, got below results
(5 nov) logger.log had logs 2014-05-01 (6 nov) logger.log (size=3.6m+) containing logs 2014-06-01 (6 nov) logger.log.2014-11-05 (size=76m) containing logs 2014-06-01
where did logs 2014-05-01 go?
.
my logger.py
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) homecoming 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 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()
i utilize above logger module in app.py
module
# ... 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
my config file looks
[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
why log rotation not happening properly? please help me out here. thanks.
python logging
No comments:
Post a Comment