Closed stchris closed 3 years ago
@stchris hey thanks for this, just stumbled upon the same issue. It'd be great to put it in the docs indeed.
@stchris my understanding is jsonlogger intended to parse and extract fields from standard formatter patterns, which are composed of %(field)s
and %(field)d
. That just parenthesizing fields worked was is artefact of an overly lenient parser. 3.8's standard formatter apparently validates the format string more specifically against the format style but it doesn't require format strings to be specified differently so much as reject format strings which should never have been accepted in the first place.
The interaction between the format string and fields extraction would probably benefit from being documented (at all) though.
Seems to be fixed with https://github.com/madzak/python-json-logger/pull/94
Indeed, this is fixed. Thanks, everyone! :+1:
It seems like with Python 3.8 the format string needs to be specified differently.
I have this small test setup:
This is
test.py
:and this
Dockerfile
:If I run
docker build -t test . && docker run -it test
it works as expected, the output is{"levelname": "INFO", "name": "root", "message": "Hello world"}
.Under Python 3.8 this results in
ValueError: Invalid format '(levelname) (name) (message)' for '%' style
. I have to change the format line to readformatter = jsonlogger.JsonFormatter("%(levelname) %(name) %(message)")
. I'm not sure if this is expected, but it might (at least) warrant an update of the documentation.