def _safe_log(log_func, msg, msg_data):
    """Sanitizes the msg_data field before logging."""
    SANITIZE = {'set_admin_password': [('args', 'new_pass')],
                'run_instance': [('args', 'admin_password')],
                'route_message': [('args', 'message', 'args', 'method_info',
                                   'method_kwargs', 'password'),
                                  ('args', 'message', 'args', 'method_info',
                                   'method_kwargs', 'admin_password')]}

    has_method = 'method' in msg_data and msg_data['method'] in SANITIZE
    has_context_token = '_context_auth_token' in msg_data
    has_token = 'auth_token' in msg_data

    if not any([has_method, has_context_token, has_token]):
        return log_func(msg, msg_data)

    msg_data = copy.deepcopy(msg_data)

    if has_method:
        for arg in SANITIZE.get(msg_data['method'], []):
            try:
                d = msg_data
                for elem in arg[:-1]:
                    d = d[elem]
                d[arg[-1]] = '<SANITIZED>'
            except __HOLE__ as e:
                LOG.info(_('Failed to sanitize %(item)s. Key error %(err)s'),
                         {'item': arg,
                          'err': e})

    if has_context_token:
        msg_data['_context_auth_token'] = '<SANITIZED>'

    if has_token:
        msg_data['auth_token'] = '<SANITIZED>'

    return log_func(msg, msg_data)
dataset/ETHPy150Open Havate/havate-openstack/proto-build/gui/horizon/Horizon_GUI/openstack_dashboard/openstack/common/rpc/common.py/_safe_log