title: Log Rotating into a Directory using Python
body: <p>I have a file called Poller.log and it's appended by log details all the time. I want this log file to be rotated everyday and limited by 30 days. Thus, the code works well.</p>
  
  <p>Now I want this logs that has been rotated to be in a folder (i.e. logs/poller.log.2011-03-04_15-36). Is there anyway to direct where this rotated file should be created?</p>
  
  <p>This python script will be executed by Cron.</p>
  
  <pre><code>import logging
  import logging.handlers
  
  LOG_FILENAME = '/home/stackoverflow/snmpdata/poller.log'
  
  # Set up a specific logger with our desired output level
  poll_logger = logging.getLogger('pollerLog')
  
  # Add the log message handler to the logger
  log_rotator = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, when='d', interval=1, backupCount=30, encoding=None, delay=False, utc=False)
  poll_logger.addHandler(log_rotator)
  
  # Roll over on application start
  poll_logger.handlers[0].doRollover()
  </code></pre>