import copy


def _safe_log(log_func, msg, msg_data):
    """Sanitizes the msg_data field before logging."""
    SANITIZE = {
                'set_admin_password': ('new_pass',),
                'run_instance': ('admin_password',),
               }
    method = msg_data['method']
    if method in SANITIZE:
        msg_data = copy.deepcopy(msg_data)
        args_to_sanitize = SANITIZE[method]
        for arg in args_to_sanitize:
            try:
                msg_data['args'][arg] = "<SANITIZED>"
            except KeyError:
                pass

    return log_func(msg, msg_data)