I'm using pygelf logging handler to integrate a Flask app with Graylog.
According to documentation, Graylog supports eight syslog severity levels, based on RFC 3164, namely:
(...)
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:
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?
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:
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. 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.
Pygelf internally holds a
dict
, that maps Python logging levels and their corresponding Graylog logging levels, ingelf.py
:My solution: In order to log on Graylog's level 5 (notify) I had to: