[英]Logging python change log level text
with the library 与图书馆
import logging
when I use the method .error(text)
or .warning(text)
, the logger writes the log level as INFO, WARNING, ERROR, etc. 当我使用方法
.error(text)
或.warning(text)
,记录器将日志级别写为INFO,WARNING,ERROR等。
I was wondering if there is a way to change the WARNING
string, for example, to WARN
(and change ERROR
as ERR
, instead). 我想知道是否有办法将
WARNING
字符串更改为WARN
(并将ERROR
改为ERR
)。
TLDR; TLDR; I want to change the Text logging level for the message ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL') in whatever I like... Is there a way to do that?
我想以我喜欢的方式更改消息的文本记录级别(“ DEBUG”,“ INFO”,“ WARNING”,“ ERROR”,“ CRITICAL”)。有没有办法做到这一点?
That comes out of the box in the logging
module, with the addLevelName
function: 这是使用
addLevelName
函数在logging
模块中开箱即用的:
logging.addLevelName(logging.WARNING, "WARN")
logging.addLevelName(logging.ERROR, "ERR")
Those name will be used by all the formatters. 这些名称将被所有格式化程序使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.