madzak / python-json-logger

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

Move log record serialization to a separate method. #89

Closed georgysavva closed 4 years ago

georgysavva commented 4 years ago

Hi. The purpose of this PR is to move the final log record serialization to a separate method from the main .format(). This will improve customization of the class. Here is my case: I want to send logs to google stackdriver from my python application. I am using json-logger to get structured log record with all extra fields, but stackdriver python library won't parse a string that contains an encoded json you need to pass a python dict object to it. So I would like to use all features of the json-logger except actual json encoding to receive python dict objects as the output. What do you think?

madzak commented 4 years ago

Hi there, sorry for the massive delay on getting back to you. I'm fine with the change, i think it's nice to put it into a function to make it more readable from a code stand point. Also it's nice to break up that massive function, but if you don't want the JSON formatted log file, then what is this package really doing for you?

It might be better to write your own formatter as this package will always just focus on JSON outputs (not to say your approach won't work, we just won't prioritize something that wouldn't support the JSON output)