title: How to limit log file size in python
body: <p>I am using windows 7 and python 2.7.
  I want to limit my log file size to 5MB.
  My app, when it starts, writes to log file, and then the app terminates.
  When my app starts again, it will write in same log file. So app is not continuously running.
  App initiates, processes and terminates.</p>
  
  <p>My code for logging is:</p>
  
  <pre><code>import logging
  import logging.handlers
  logging.basicConfig(filename=logfile.log, level="info", format='%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
  logging.info("*************************************************")
  </code></pre>
  
  <p>I tried with <strong>RotatingFileHandler</strong> but it didn't work</p>
  
  <pre><code>logging.handlers.RotatingFileHandler(logFile, mode='a', maxBytes=5*1024*1024, backupCount=2, encoding=None, delay=0)
  </code></pre>
  
  <p>So, how can I enforce a file size limit in python?</p>