madzak / python-json-logger

Json Formatter for the standard python logger
BSD 2-Clause "Simplified" License
1.7k stars 231 forks source link

Workaround logging.LogRecord.msg type of str #133

Closed bringhurst closed 2 years ago

bringhurst commented 2 years ago

I would love to avoid doing this, but I can't seem to find a nicer alternative (without changing the API). Any thoughts on alternatives would her appreciated.

Note that this may be a breaking change for typed code. They'll need a "# type: ignore" comment if they want to pass in something other than a LogRecord and exercise this functionality.

See the related comment over at: https://github.com/madzak/python-json-logger/issues/118#issuecomment-1030888274

Note that logging.LogRecord.msg and logging.LogRecord.message are both type of str in typeshed (https://github.com/python/typeshed/blob/b88a6f19cdcf031be8135941b940f839e13064d8/stdlib/logging/__init__.pyi#L343) , but we treat them as (optional) dicts here.