tags:

views:

27

answers:

2

This is my config file:

[loggers]
keys=root

[handlers]
keys=TimedRotatingFileHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=DEBUG
handlers=TimedRotatingFileHandler

[handler_TimedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=simpleFormatter
args=('driver.log', 'midnight', 1, 30)

[formatter_simpleFormatter]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=

In my code I setup and use the logger like this:

import logging
import logging.config

logging.config.fileConfig('logging.conf')
logging.info('Some message...')

Messages are logged to the file I specify (driver.log), but the rotations at midnight never happen.

Must the process be running at midnight for the rotation to occur? This is a batch process that I run every 15 minutes and it is never actually running at midnight.

+1  A: 

I would guess this really only happens when the process is running at midnight. In your case (cronjob not running very long), you should go with a simple log file, where the current date is added to the logfilename. This way, a "rollover" happens automatically.

ZeissS
Yeah, I was trying not to reinvent the wheel since I also need these files to recycle after some time.
cope360
+3  A: 

The answer is that the process must be running all the time for this to work properly.

From http://bytes.com/topic/python/answers/595931-timedrotatingfilehandler-isnt-rotating-midnight:

Rotating should happen when the logging process creates the handler before midnight and makes a logging call destined for that handler after midnight.

cope360
+1 sounds like the issue.
Matt Williamson