def install_remote_handler(host, port, prefix=None):  # pragma no cover
    """
    Installs a handler for logging to `host` on `port` with `prefix`.
    Returns True if connecting to the remote host was successful.

    host: string
        Host to send log requests to.

    port: int
        Port on `host` to send log requests to.

    prefix: string
        Added to the log record for use on `host`.
        The default prefix is ``pid@hostname``.
    """
    if prefix is None:
        prefix = '%s@%s' % (os.getpid(), socket.gethostname())

    try:
        sock = socket.create_connection((host, port))
    except Exception as exc:
        logging.error("Can't connect to logging server at %s:%s: %s",
                      host, port, exc)
        return False
    sock.close()

    handler = _RemoteHandler(host, port, prefix)
    root = logging.getLogger()
    root.addHandler(handler)

    my_pid = os.getpid()
    if my_pid not in _REMOTE_HANDLERS:
        # Remove any handlers from our parent process due to a fork.
        for pid, handlers in _REMOTE_HANDLERS.items():
            for handler in handlers:
                try:
                    root.removeHandler(handler)
                    handler.close()
                except KeyError:  # Apparently it's not there anymore.
                    pass
                except Exception as exc:
                    logging.warning("Can't remove inherited remote log handler:"
                                    " %s", str(exc) or repr(exc))
            del _REMOTE_HANDLERS[pid]
        _REMOTE_HANDLERS[my_pid] = []
    _REMOTE_HANDLERS[my_pid].append(handler)

    return True


# Called by the remote process.
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.util/src/openmdao/util/log.py/install_remote_handler/original