import logging


def loglevel(level):
    """
    Converts a string representing the logging level to corresponding number.

    This is primarily used as the type of an argument in argparse. See
    https://docs.python.org/3/library/logging.html#logging-levels for a list
    of logging levels.

    Args:
        level (str): logging level

    Returns:
        int: Numeric logging level

    Raises:
        ValueError: If `level` is not a recognized logging level.
    """
    numeric_level = getattr(logging, level.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError('Invalid log level: %s' % loglevel)
    return numeric_level