def _LogErrorsToConsole(base):
  class wrapped(base): # pylint: disable=C0103
    """Log handler that doesn't fallback to stderr.

    When an error occurs while writing on the logfile, logging.FileHandler
    tries to log on stderr. This doesn't work in Ganeti since stderr is
    redirected to a logfile. This class avoids failures by reporting errors to
    /dev/console.

    """
    def __init__(self, console, *args, **kwargs):
      """Initializes this class.

      @type console: file-like object or None
      @param console: Open file-like object for console

      """
      base.__init__(self, *args, **kwargs)
      assert not hasattr(self, "_console")
      self._console = console

    def handleError(self, record): # pylint: disable=C0103
      """Handle errors which occur during an emit() call.

      Try to handle errors with FileHandler method, if it fails write to
      /dev/console.

      """
      try:
        base.handleError(record)
      except Exception: # pylint: disable=W0703
        if self._console:
          try:
            # Ignore warning about "self.format", pylint: disable=E1101
            self._console.write("Cannot log message:\n%s\n" %
                                self.format(record))
          except Exception: # pylint: disable=W0703
            # Log handler tried everything it could, now just give up
            pass

  return wrapped


#: Custom log handler for writing to console with a reopenable handler
Create wrapper class writing errors to console.
dataset/ETHPy150Open ganeti/ganeti/lib/utils/log.py/_LogErrorsToConsole