-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
We're able to configure Application.log_datefmt and Application.log_format options but with something like this configuration:
c.Application.log_datefmt = '%Y-%m-%dT%H:%M:%S'
c.Application.log_format = '%(levelname)s %(asctime)s.%(msecs).03dZ [%(name)s %(module)s:%(lineno)d] %(message)s'You get logs like this:
WARNING 2020-10-07T16:01:41.630Z [SingleUserNotebookApp filemanager:266] Invalid ctime 1601063354730.0 for /home/jovyan/test2.txt
INFO 2020-10-07T16:01:41.632Z [SingleUserNotebookApp log:174] 200 GET /user/5e18a4193f4a3f001127f809/api/contents/?type=directory&_=1602086500971 ([email protected]) 387.15ms
INFO 2020-10-07T16:01:45.283Z [SingleUserNotebookApp log:174] 200 GET /user/5cc87910c20b7200111d7315/metrics ([email protected]) 3.22ms
We're using LogDNA and with that config we can at least filter logs by level but what we'd like to be able to do is have json log formatting so that individual fields can be used in query filters to the logging system (I think LogDNA is or at least used to use ElasticSearch under the covers).
If this is already possible with the notebook app config or tornado I'm not sure how to do it easily.
I see there is a log formatter defined here:
notebook/notebook/notebookapp.py
Line 705 in 498b0bc
| _log_formatter_cls = LogFormatter |
But I'm not sure where that _log_formatter_cls attribute gets used, I don't see it in jupyter-core or tornado.
https://www.tornadoweb.org/en/stable/log.html doesn't mention anything about being able to define a different JSON log format. I see some stuff in https://dchua.com/2016/07/19/logging-tornado-logs-to-graylog/ but I was wondering how easy it would be to just add an option to the notebook app to use json logging and then use a formatter / handler from something like https://pypi.org/project/json-logging/ or https://github.com/madzak/python-json-logger.