[英]Pygelf - How to send logs with “notice” severity level
I'm using pygelf logging handler to integrate a Flask app with Graylog . 我正在使用pygelf日志记录处理程序将Flask应用程序与Graylog集成在一起 。
According to documentation , Graylog supports eight syslog severity levels, based on RFC 3164 , namely: 根据文档 ,Graylog支持基于RFC 3164的八个syslog严重级别,即:
(...)
Numerical Severity
Code
0 Emergency: system is unusable
1 Alert: action must be taken immediately
2 Critical: critical conditions
3 Error: error conditions
4 Warning: warning conditions
5 Notice: normal but significant condition
6 Informational: informational messages
7 Debug: debug-level messages
(...)
While Graylog supports level 5, which is notice
, Python's logging package does not seem to have neither a notice()
logging method (like info()
or debug()
) nor a corresponding logging level defined: 虽然Graylog支持5级(即
notice
,但Python的日志记录包似乎既没有notification notice()
日志记录方法(如info()
或debug()
),也没有定义相应的日志记录级别:
CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0
Question : Is there a way to force pygelf
to use the notice
log level? 问题 :是否有一种方法可以强制
pygelf
使用notice
日志级别?
Additional background: 其他背景:
I'm using Flask framework, which by default uses log levels 6 ( info
) and 7 ( debug
) to log it's own internal http request data that looks like: 我正在使用Flask框架,默认情况下使用日志级别6(
info
)和7( debug
)来记录它自己的内部http请求数据,如下所示:
101.101.101.101 - - [03/Sep/2019 14:15:55] "GET /static/images/favicon.ico HTTP/1.0" 200 -
Because of those internal logs, my own info
and debug
-level logs get lost in the crowd. 由于这些内部日志,我自己的
info
和debug
级别的日志在人群中迷路了。 I don't want to completely filter them off, but I still want to have some distinct informative logging level that's not as high as warning
- that's why I could use a notice
-level logging, which unfortunately I can't use out-of-the-box. 我不想完全过滤掉它们,但我仍然希望拥有一些不如
warning
级别高的独特信息日志记录级别-这就是为什么我可以使用notice
级别的日志记录的原因,不幸的是,我不能使用超出范围的日志记录盒子。
Pygelf internally holds a dict
, that maps Python logging levels and their corresponding Graylog logging levels, in gelf.py
: Pygelf内部拥有
dict
,它在gelf.py
中映射了Python日志记录级别及其对应的Graylog日志记录级别:
LEVELS = {
logging.DEBUG: 7,
logging.INFO: 6,
logging.WARNING: 4,
logging.ERROR: 3,
logging.CRITICAL: 2
}
My solution : In order to log on Graylog's level 5 (notify) I had to: 我的解决方案 :为了登录Graylog的5级(通知),我必须:
from pygelf import GelfTcpHandler, gelf
NOTIFY = 35
GELF_NOTIFY_LEVEL = 5
(...)
gelf.LEVELS.update({NOTIFY: GELF_NOTIFY_LEVEL})
handler = GelfTcpHandler(
...
)
logging.getLogger().addHandler(handler)
import logging
logger = logging.getLogger()
(...)
# logger.debug('Old logging to "debug"-level logger')
logger.log(NOTIFY, 'New logging to "notify"-level logger')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.