[Tutor] TimedRotatingFileHandler donot rollover
viktor vraniak
tyctor at post.cz
Fri Nov 10 19:02:44 CET 2006
hallo
i have (i thing) little problem with TimedRotatingFileHandler
i have following code to get mylogger:
def MyLogger(req, logpath, logfilename):
logdir = DEFAULT_LOG_DIR
backupcount = DEFAULT_LOG_BACKUPS
fmt='%(asctime)s %(msecs)d %(levelname)-8s %(message)s'
datefmt='%d%m%Y %H:%M:%S'
path = os.path.join(logdir, logpath)
if not os.path.exists(path):
try:
os.makedirs(path, 0775)
except:
exctype, value = sys.exc_info()[:2]
req.log_error("%s, %s" % (str(exctype), str(value)))
raise exctype, value
filename = os.path.join(path, logfilename)
rootLogger = logging.getLogger('MyLogger')
if not rootLogger.handlers:
rotatingLogger = logging.handlers.TimedRotatingFileHandler(filename, "M", 1, backupcount)
formatter = logging.Formatter(fmt=fmt,datefmt=datefmt)
rotatingLogger.setFormatter(formatter)
rootLogger.addHandler(rotatingLogger)
if rotatingLogger.shouldRollover(None):
rotatingLogger.doRollover()
rootLogger.setLevel(loglevel)
return rootLogger
but rollover never occurs. (when = 'M' , interval = 1 is for testing)
i use logginng in my web application, which runs under mod_python, python 2.4
when i try to log values from inside TimedRotatingFileHandler
then i found out that time is always smaller than rolloverAt
i want to use logging for midnight rottating, does anyone has this problem too?
thanks for help or any answer
tyctor
More information about the Tutor
mailing list