我读了Python Logging HOWTO,有一个描述我不明白:
If you want to set the logging level from a command-line option such as:
--log=INFO
and you have the value of the parameter passed for
--log
in some variable loglevel, you can use:getattr(logging, loglevel.upper())
to get the value which you’ll pass to
basicConfig()
via the level argument.
这是什么意思?没有例子,如果有人能举一个就好了。在
我可以设置这个级别吗?在
logging --log=INFO
假设您正在使用
argparse
之类的东西来定义命令行参数:log
选项的参数应该是logging
模块中定义的一个级别常量;getattr(logging, loglevel.upper())
将是一种获取字符串值的方法。在相关问题 更多 >
编程相关推荐