确定是否在Python中将根记录器设置为DEBUG级别? [英] Determining if root logger is set to DEBUG level in Python?

查看:74
本文介绍了确定是否在Python中将根记录器设置为DEBUG级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果使用以下命令行参数将日志记录模块设置为DEBUG:

If I set the logging module to DEBUG with a command line parameter like this:

if (opt["log"] == "debug"):
  logging.basicConfig(level=logging.DEBUG)

以后如何判断记录器是否设置为DEBUG?我正在写一个装饰器 如果向其传递了True标志,将为函数计时,如果未给出标志,则默认 在根记录器设置为DEBUG时打印时间信息.

How can I later tell if the logger was set to DEBUG? I'm writing a decorator that will time a function if True flag is passed to it, and if no flag is given, it defaults to printing timing information when the root logger is set to DEBUG.

推荐答案

logging.getLogger().getEffectiveLevel()

logging.getLogger()不带参数的将获取根级别记录器.

logging.getLogger() without arguments gets the root level logger.

http://docs.python.org/library/logging. html#logging.Logger.getEffectiveLevel

这篇关于确定是否在Python中将根记录器设置为DEBUG级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆