import logging


def error_to_str(e):
    """Tries to convert error message to string, handling unicode errors along the way and logging them"""
    try:
        return str(e)
    except UnicodeError as ue:
        logging.warning("Error converting error %r to str: %s", e, ue)
        try:
            return str(e).encode("UTF-8")
        except UnicodeError as ue2:
            logging.warning("Error converting error %r to unicode: %s", e, ue2)
            return "Error %r, args %r" % (e, e.args)