import logging


def yaml_from_csv(csv_dict):
    """
    Defining necessary to retrieve a value (given by field name) from a dict

    Ex (in YAML file):
    my_key: !from_csv field_name
    """
    def _yaml_loader(loader, node, csv_dict=csv_dict):
        # If value not exists, store the error
        if csv_dict.get(node.value, None) is None:
            logging.error(
                "YAML file CSV reference '%s' missing. Can be given with option \
                '--extra-config=<YAML>'. YAML content example: '%s: <value>'",
                node.value,
                node.value)
            # We don't replace value because we can't...
            return node.value
        else:
            # No error, we return the value
            return csv_dict[node.value]

    return _yaml_loader