You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
dockerflow.logging.JsonLogFormatter is weird about %s style logging #29
▶ DJANGO_LOGGING_USE_JSON=False DJANGO_LOGGING_DEFAULT_LEVEL=DEBUG ./manage.py shell
Python 3.6.5 (default, Mar 30 2018, 06:41:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import logging
In [2]: logger = logging.getLogger("myproject")
In [3]: logger.info("Hi!")
INFO 2018-11-09 18:19:07,726 myproject Hi!
In [4]: logger.info("Hi %s", "peter")
INFO 2018-11-09 18:19:13,941 myproject Hi peter
In [5]: logger.info("Hi %s", {'name': 'Peter'})
INFO 2018-11-09 18:19:20,103 myproject Hi {'name': 'Peter'}
So if you still care @peterbe#37 will make it easier for you to override this behavior, there is a is_value_jsonlike method you can override on the JsonLogFormatter class.
Activity
peterbe commentedon Nov 9, 2018
Contrast that with regular "verbose" logging:
peterbe commentedon Nov 9, 2018
The "cause" of this is that the
record.getMessage()here becomes this string:"Hi {'name': 'Peter'}"and because of the line:
...it decides to not include the message.
I'm trying to parse that code comment two lines above but struggling to understand what it means
... is not already a JSON blob.peterbe commentedon Nov 9, 2018
Because I'm timely desperate for a solution, here's how I solved it:
By making sure the logging message string has an extra character that is not
}, it works.diox commentedon Sep 26, 2019
So if you still care @peterbe #37 will make it easier for you to override this behavior, there is a
is_value_jsonlikemethod you can override on theJsonLogFormatterclass.