def emit(self, record): """Emit the provided record to the kafka_client producer.""" # drop kafka logging to avoid infinite recursion if 'kafka.' in record.name: return try: # apply the logger formatter msg = self.format(record) self.producer.send(self.topic, {'message': msg}) self.flush(timeout=1.0) except Exception as e: Handler.handleError(self, record)
def _safewrap_handler(self, handler: logging.Handler) -> None: # Make the logger handlers dump internal errors to # :data:`sys.__stderr__` instead of :data:`sys.stderr` to circumvent # infinite loops. class WithSafeHandleError(logging.Handler): def handleError(self, record: logging.LogRecord) -> None: try: traceback.print_exc(None, sys.__stderr__) except IOError: pass # see python issue 5971 handler.handleError = WithSafeHandleError().handleError # type: ignore
def handleError(self, record): if self.__conn and self.__conn.is_open: self.__conn.close() self.__conn = None Handler.handleError(self, record)