RotatingFileHandler does not continue logging after error encountered
<pre><code>Traceback (most recent call last):
File "/usr/lib64/python2.6/logging/handlers.py", line 76, in emit
    if self.shouldRollover(record):
File "/usr/lib64/python2.6/logging/handlers.py", line 150, in       shouldRollover
     self.stream.seek(0, 2)  #due to non-posix-compliant Windows feature
ValueError: I/O operation on closed file
</code></pre>

<p>I have a line in my script:</p>

<pre><code>handler = logging.handlers.RotatingFileHandler(cfg_obj.log_file,maxBytes = maxlog_size, backupCount = 10)
</code></pre>

<p>It runs fine when there are no error messages. But when there's an error log, the logs after the error are not written to the file unless the process is restarted. We do not want to restart the process every time there is an error. 
Thanks for your help in advance!</p>

<p>I highly recommend you to use a configuration file. The configuration code below "logging.conf" has different handlers and formatters just as example: </p>

<pre><code>[loggers]
keys=root

[handlers]
keys=consoleHandler, rotatingFileHandler

[formatters]
keys=simpleFormatter, extendedFormatter

[logger_root]
level=DEBUG
handlers=consoleHandler, rotatingFileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_rotatingFileHandler]
class=handlers.RotatingFileHandler
level=INFO
formatter=extendedFormatter
args=('path/logs_file.log', 'a', 2000000, 1000)


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

[formatter_extendedFormatter]
format= %(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(funcName)s() %(message)s
datefmt=
</code></pre>

<p>Now how to use it "main.py":</p>

<pre><code>import logging.config

# LOGGER
logging.config.fileConfig('path_to_conf_file/logging.conf')
LOGGER = logging.getLogger('root')
try:
    LOGGER.debug("Debug message...")
    LOGGER.info("Info message...")   
except Exception as e:    
    LOGGER.exception(e)
</code></pre>

<p>Let me know if you need more help.</p>

python logging