Customizing JSON format
Closed this issue · 2 comments
kbakk commented
Because our logging requirements differ from the JSON output of the default (JSONLogFormatter), it would be verify useful to be able to change it.
I initially tried with changing json_logging.JSON_SERIALIZER
, however this (for example) doesn't give me option to change how the stack trace is formatted.
bobbui commented
Could you please let me know your JSON format requirement in more detail, we can work out a solution together.
Thanks
kbakk commented
We are working in my company to decide on what format to use - we currently have something like this
{
"@timestamp": "2019-01-26T11:29:11.676573",
"level": "ERROR",
"message": "Nothing to see here",
"caller": "test_json_logger.py::test_log_output_json",
"data": {
"python.logger_name": "tests.test_json_logger",
"python.module": "test_json_logger",
"python.funcName": "test_log_output_json",
"python.filename": "test_json_logger.py",
"python.lineno": 42,
"python.thread": "MainThread[4576691648]",
"python.pid": 3419,
"divide_by": 0,
"python.exc_info": "Traceback (most recent call last):\n File \"/Users/kristofferb/Code/json-logging/tests/test_json_logger.py\", line 40, in test_log_output_json\n 1/0\nZeroDivisionError: division by zero\n"
}
}
but the jury is still out.
I've submitted PR #14 - appreciate if you could take a look. It lets the user customize the logging format, and it is easy to modify it later if needed.