cp_logging.py 文件源码

python
阅读 61 收藏 0 点赞 0 评论 0

项目:sdk-samples 作者: cradlepoint 项目源码 文件源码
def _process_level(value):
    """
    Given an input (as string or int) convert to LOGGING level value

    :param value:
    """

    # allow settings.ini to use names like level=debug, logging._nameToLevel[] will throw exception
    name_to_level = {
        'CRITICAL': logging.CRITICAL,
        'ERROR': logging.ERROR,
        'WARN': logging.WARNING,
        'WARNING': logging.WARNING,
        'INFO': logging.INFO,
        'DEBUG': logging.DEBUG,
        'NOTSET': logging.NOTSET
    }

    if isinstance(value, str):
        # handle the LOGGING level, such as INFO or DEBUG or 10
        value = unquote_string(value)
        try:
            # start assuming is int, but it is probably str of int
            value = int(value)

        except ValueError:
            # if here, then try if string like INFO, force to UPPER()
            try:
                value = name_to_level[value.upper()]

            except KeyError:
                raise ValueError("Logging level must as expected by Python LOGGING" +
                                 "module - not {}".format(value))

    if not isinstance(value, int):
        raise TypeError("Logging value must be string or int")

    return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号