title: Handle and re-raise exceptions thrown by python logging module
body: <h2>Question</h2>
  
  <p>How do I write a custom handler for a python <code>logging</code> logger that will catch an <code>IOError</code> caused by a sudden inability to write logging information to file and re-raise the error as a different type?</p>
  
  <h2>Further information</h2>
  
  <p>I'm reading and converting a large repository of raw data and it's important for me to record the process (python <code>logging</code> module). If logging fails because of some error, e.g. <code>IOError</code>, I would like the application to gracefully exit. Over the weekend, the network location where I write my log files crashed and the conversion process gamely continued.</p>
  
  <p>There can be an <code>IOError</code> thrown by other components in my code (e.g. a raw file to convert for a given hour is not present indicating that the detector was down for that given period in time) that are not important and can be ignored. I catch these errors and continue with the next hour of data.</p>
  
  <p>If the logger threw a different, custom exception I could handle it separately. Something like (disclaimer: this doesn't work):</p>
  
  <pre class="lang-python prettyprint-override"><code>class WarningFileHandler(logging.FileHandler):
      """File handler for only writing WARNING log information to disk"""
  
      def __init__(self,filename,mode='a',encoding=None,delay=False):
          logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  
      def emit(self, record):
          # Filter out all record objects that are not at the logging.WARNING level.
          if not record.levelno == logging.WARNING:
              return
          try:
              logging.FileHandler.emit(self, record)
          except IOError as e:
              # The logger cannot write successfully to disk (e.g. a network
              # resource becomes unavailable).
              raise LoggerIOError("[ERROR NO {0}: {1}]. Logger write "
                      "failure.".format(e.errno,e.strerror))
  </code></pre>
  
  <p><code>LoggerIOError</code> is a simple, custom exception.</p>
  
  <pre class="lang-python prettyprint-override"><code>class LoggerIOError(Exception):
      """Logger IOError"""
      pass
  </code></pre>
  
  <p>Can anyone provide some help or advice? I don't have much experience with the <code>logging</code> module and so I may be overlooking something simple. </p>
  
  <p><code>logging.raiseExceptions</code> should be its default value of <code>True</code>. </p>
  
  <h3>Details</h3>
  
  <p>OS/Python details:</p>
  
  <ul>
  <li>Windows 7</li>
  <li>Python 2.7</li>
  </ul>
  
  <p>Thanks!</p>