bobbui / json-logging-python

Cloud-native distributed Python logging library to emit JSON log that can be easily indexed by logging infrastructure
Apache License 2.0
303 stars 62 forks source link

customize JsonLogFormatter in a fastapi app #82

Closed fmieres closed 3 years ago

fmieres commented 3 years ago

I would like to override this method on application log level : (just remove the ''.join(... , basically it makes it easier to read error logs for me.

class CustomJSONLog(json_logging.JSONLogFormatter):
    @classmethod
    def format_exception(cls, exc_info):
        return traceback.format_exception(*exc_info) if exc_info else ''

But since I am using a fast api app, i only get to override the JSONRequestLogFormatter, so i cant override the non web log. And uvicorn errors go trough the latter.

Is there anything close to json_logging.init_request_instrument(app, custom_non_web_formatter=CustomJSONLog) available ?

bobbui commented 3 years ago

formatter class can be overriden by passing custom_formatter param to init_fastapi method