[issue33510] [logging] add JSON log formatter

Steve R. Hastings report at bugs.python.org
Mon May 14 22:57:47 EDT 2018


Steve R. Hastings <steveha at users.sourceforge.net> added the comment:

The solution recommended in the logging cookbook does not do the same thing as I have proposed.

I have proposed a logging handler that emits JSON suitable for ingestion by a log collection system.  With the JSON formatter, all log events, no matter their source, are written completely in JSON.  This includes log events from already-written library functions that have no expectation of JSON output.  Also the JSON formatter writes timestamps in the now-universally-understood RFC3339 format, the easiest date format to parse.

The logging cookbook solution is that the user must explicitly write JSON data into the message line of each call to the logging code.  This would make some or all of the message field into JSON but does not solve the problem of logging in JSON; the other fields of the log file would remain non-JSON.

A company that is using a log collection system might need the logs to be pure JSON.  The proposed JSON formatter solves that problem.

P.S. Here is a blog posting on why it is useful to log in pure JSON:

https://journal.paul.querna.org/articles/2011/12/26/log-for-machines-in-json/

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33510>
_______________________________________


More information about the Python-bugs-list mailing list