def capture_stdio(logger, **kwargs):
 sys.excepthook = (lambda *exc_info: logger.critical(_('UNCAUGHT EXCEPTION'), exc_info=exc_info))
 stdio_files = [sys.stdin, sys.stdout, sys.stderr]
 console_fds = [h.stream.fileno() for (_junk, h) in getattr(get_logger, 'console_handler4logger', {}).items()]
 stdio_files = [f for f in stdio_files if (f.fileno() not in console_fds)]
 with open(os.devnull, 'r+b') as nullfile:
  for f in stdio_files:
   try:
    f.flush()
   except IOError:
    pass
   try:
    os.dup2(nullfile.fileno(), f.fileno())
   except OSError:
    pass
 if kwargs.pop('capture_stdout', True):
  sys.stdout = LoggerFileObject(logger)
 if kwargs.pop('capture_stderr', True):
  sys.stderr = LoggerFileObject(logger, 'STDERR')

def capture_stdio ( logger , ** kwargs ) : sys . excepthook = ( lambda * exc_info : logger . critical ( _ ( 'UNCAUGHT EXCEPTION' ) , exc_info = exc_info ) ) stdio_files = [ sys . stdin , sys . stdout , sys . stderr ] console_fds = [ h . stream . fileno ( ) for ( _junk , h ) in getattr ( get_logger , 'console_handler4logger' , { } ) . items ( ) ] stdio_files = [ f for f in stdio_files if ( f . fileno ( ) not in console_fds ) ] with open ( os . devnull , 'r+b' ) as nullfile : for f in stdio_files : try : f . flush ( ) except IOError : pass try : os . dup2 ( nullfile . fileno ( ) , f . fileno ( ) ) except OSError : pass if kwargs . pop ( 'capture_stdout' , True ) : sys . stdout = LoggerFileObject ( logger ) if kwargs . pop ( 'capture_stderr' , True ) : sys . stderr = LoggerFileObject ( logger , 'STDERR' )
log unhandled exceptions .