获取命名日志级别的列表

编程入门 行业动态 更新时间:2024-10-15 04:26:10
本文介绍了获取命名日志级别的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的应用程序中,我正在使用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.

更多推荐

获取命名日志级别的列表

本文发布于:2023-11-30 08:59:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649439.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:级别   列表   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!