nhairs / python-json-logger

JSON Formatter for Python Logging
https://nhairs.github.io/python-json-logger/
BSD 2-Clause "Simplified" License
28 stars 5 forks source link

Defaults parameter is ignored #24

Open bharel opened 2 months ago

bharel commented 2 months ago

The defaults parameter that Logging.Formatter takes is ignored. We can make it work 😄

I can submit a patch :-)

nhairs commented 2 months ago

Hi @bharel,

I'm not opposed to giving the defaults argument a purpose, but what purpose would that be?

Keep in mind that we already have the static_fields parameter which is not going away any time soon as I won't break backwards compatibility without good reason.

bharel commented 2 months ago

Exactly the same purpose that it has in the standard library - provide a default value for optional fields.

Atm if a field doesn't exist it is returned as null.

Static fields are not doing the same thing - they always exist and override the other values.

nhairs commented 2 months ago

Okay I think I understand what you're getting at.

Essentially from the interactions of parsing required fields, renaming fields, and the actual fields on a log message it's possible that a field becomes None because of a missing value.

Which means what I think you're proposing is that we use the defaults dict to provide backup values for any field.

In which case I'd be happy to accept a patch :) In case you haven't seen it you can find the contributing guidelines here