def handle(self):
        """ Handle log requests until connection closed. """
        # An initial 'unused' connection will be made by the client to see
        # if it can connect. We reduce logging noise by ignoring these.
        makeLogRecord = logging.makeLogRecord
        logger = logging.getLogger('remote')
        conn = self.connection
        recv = conn.recv
        peer = None

        while True:
            try:
                data = recv(4)
            except Exception:
                return  # Typically [Errno 10054] on Windows.
            if len(data) < 4:
                break

            if peer is None:
                host, port = conn.getpeername()
                try:
                    host, aliases, addrs = socket.gethostbyaddr(host)
                except Exception as exc:
                    logger.debug('gethostbyaddr(%s) failed: %s',
                                 host, str(exc) or repr(exc))
                peer = '%s:%s' % (host, port)
                logger.info('New logging connection from %s', peer)

            slen = unpack('>L', data)[0]
            data = recv(slen)
            slen -= len(data)
            msg = data
            while slen:
                data = recv(slen)
                slen -= len(data)
                msg = ''.join((msg, data))

            try:
                obj = loads(msg)
                record = makeLogRecord(obj)
            except Exception as exc:
                logger.exception("Can't process log request from %s: %s",
                                 peer, exc)
            else:
                prefix = record.prefix
                name = record.name
                if name != prefix:
                    record.name = '[%s] %s' % (prefix, name)
                else:
                    record.name = '[%s]' % prefix
                logger.handle(record)

        conn.close()
        if peer is not None:
            logger.info('Logging connection from %s closed', peer)
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.util/src/openmdao/util/log.py/_LogHandler.handle/original