title: How to log everything into a file using RotatingFileHandler by using logging.conf file?
body: <p>I am trying to use <code>RotatingHandler</code> for our logging purpose in Python. I have kept backup files as 500 which means it will create maximum of 500 files I guess and the size that I have set is 2000 Bytes (not sure what is the recommended size limit is).</p>
  
  <p>If I run my below code, it doesn't log everything into a file. I want to log everything into a file - </p>
  
  <pre><code>#!/usr/bin/python
  
  import logging
  import logging.handlers
  
  LOG_FILENAME = 'testing.log'
  
  # Set up a specific logger with our desired output level
  my_logger = logging.getLogger('agentlogger')
  
  # Add the log message handler to the logger
  handler = logging.handlers.RotatingFileHandler(LOG_FILENAME, maxBytes=2000, backupCount=100)
  
  # create a logging format
  formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
  handler.setFormatter(formatter)
  
  my_logger.addHandler(handler)
  
  my_logger.debug('debug message')
  my_logger.info('info message')
  my_logger.warn('warn message')
  my_logger.error('error message')
  my_logger.critical('critical message')
  
  # Log some messages
  for i in range(10):
      my_logger.error('i = %d' % i)
  </code></pre>
  
  <p>This is what gets printed out in my <code>testing.log</code> file - </p>
  
  <pre><code>2013-11-22 12:59:34,782 - agentlogger - WARNING - warn message
  2013-11-22 12:59:34,782 - agentlogger - ERROR - error message
  2013-11-22 12:59:34,782 - agentlogger - CRITICAL - critical message
  2013-11-22 12:59:34,782 - agentlogger - ERROR - i = 0
  2013-11-22 12:59:34,782 - agentlogger - ERROR - i = 1
  2013-11-22 12:59:34,783 - agentlogger - ERROR - i = 2
  2013-11-22 12:59:34,783 - agentlogger - ERROR - i = 3
  2013-11-22 12:59:34,783 - agentlogger - ERROR - i = 4
  2013-11-22 12:59:34,783 - agentlogger - ERROR - i = 5
  2013-11-22 12:59:34,783 - agentlogger - ERROR - i = 6
  2013-11-22 12:59:34,784 - agentlogger - ERROR - i = 7
  2013-11-22 12:59:34,784 - agentlogger - ERROR - i = 8
  2013-11-22 12:59:34,784 - agentlogger - ERROR - i = 9
  </code></pre>
  
  <p>It doesn't print out <code>INFO</code>, <code>DEBUG</code> message into the file somehow.. Any thoughts why it is not working out?</p>
  
  <p>And also, right now, I have defined everything in this python file for logging purpose. I want to define above things in the <code>logging conf</code> file and read it using the <code>fileConfig()</code> function. I am not sure how to use the <code>RotatingFileHandler</code> example in the <code>logging.conf</code> file?</p>
  
  <p><strong>UPDATE:-</strong></p>
  
  <p>Below is my updated Python code that I have modified to use with <code>log.conf</code> file - </p>
  
  <pre><code>#!/usr/bin/python
  
  import logging
  import logging.handlers
  
  my_logger = logging.getLogger(' ')
  my_logger.config.fileConfig('log.conf')
  
  my_logger.debug('debug message')
  my_logger.info('info message')
  my_logger.warn('warn message')
  my_logger.error('error message')
  my_logger.critical('critical message')
  
  # Log some messages
  for i in range(10):
      my_logger.error('i = %d' % i)
  </code></pre>
  
  <p>And below is my <code>log.conf file</code> - </p>
  
  <pre><code>[loggers]
  keys=root
  
  [handlers]
  keys=logfile
  
  [formatters]
  keys=logfileformatter
  
  [logger_root]
  level=DEBUG
  handlers=logfile
  
  [logger_zkagentlogger]
  level=DEBUG
  handlers=logfile
  qualname=zkagentlogger
  propagate=0
  
  [formatter_logfileformatter]
  format=%(asctime)s %(name)-12s: %(levelname)s %(message)s
  
  [handler_logfile]
  class=handlers.RotatingFileHandler
  level=NOTSET
  args=('testing.log',2000,100)
  formatter=logfileformatter
  </code></pre>
  
  <p>But whenever I compile it, this is the error I got on my console - </p>
  
  <pre><code>$ python logtest3.py
  Traceback (most recent call last):
    File "logtest3.py", line 6, in &lt;module&gt;
      my_logger.config.fileConfig('log.conf')
  AttributeError: 'Logger' object has no attribute 'config'
  </code></pre>
  
  <p>Any idea what wrong I am doing here?</p>