Hi all,
I'm trying to extend the formatter for console logging with custom keys. But I've run into two problems while doing that:
1) Root log messages of course don't provide these custom keys in their
extra dict, so they throw errors. Looking at the official Python documentation, it is possible to specify
defaults for a formatter (
https://docs.python.org/3/library/logging.html#logging.Formatter), but Django doesn't support such a thing when trying to set it via the
settings.py (as in: the formatters entry in the
LOGGING specification in the
settings.py doesn't support this).
2) So I looked into using that formatter only for my own log messages, for which I can control the extra dict passed to them. But it doesn't seem to be possible to provide two formatters for a single handler (kinda makes sense, since at that point, how would the handler choose the formatter?) But if I specify two different handlers of type logging.StreamHandler, only one of them seems to work (and the other handler's messages just aren't visible in the console output).
Does anyone have a solution for this?
If not, do people think it's worth requesting support for the defaults field for formatters specified in the settings.py LOGGING configuration?
Thanks!
-M