获取命名日志级别的列表 [英] get list of named loglevels

查看:154
本文介绍了获取命名日志级别的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在使用python.logging进行记录.

In my application, I'm using python.logging for logging.

现在,我想以交互方式控制日志级别,因此我创建了一个组合框帽子,使用户可以选择" ERROR "," WARN "," INFO ,...

Now I want to control the loglevel interactively, so i created a combobox hat lets the user select "ERROR", "WARN", "INFO",...

我真正不喜欢的是,当前组合框中的值是硬编码的. 相反,Ii希望拥有所有命名"日志级别的列表(例如,既是系统默认值,又是通过logging.addLevelName添加的默认值;但不是伪造的日志级别,例如" Level 42 ")

What I don't really like is that currently the values in the combobox are hardcoded. Instead,Ii would like to have a list of all "named" loglevels (e.g. both the system defaults, but also those added via logging.addLevelName; but not the fake generated loglevels like "Level 42")

到目前为止,我想出的最好的方法是使用logging._levelNames字典.

The best I have come up with so far is to use the logging._levelNames dictionary.

但是,这似乎是一个私人成员,我不知道如何直接访问它.

But then this seems to be a private member, and I somehow have a bad feeling accessing it directly.

所以我的问题是:在Python中列出所有当前定义的命名"日志级别的正确方法是什么.

So my question is: what's the proper way to list all currently defined "named" loglevels in Python.

推荐答案

由于您仅在读取值,因此logging._levelNames对我来说是一个合适的解决方案.继续使用logging.addLevelName设置新值.

As you are only reading values, logging._levelNames looks an appropriate solution to me. Keep going with logging.addLevelName for setting new values though.

这篇关于获取命名日志级别的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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