Minimal configuration for uvicorn/fastapi logs in JSON format without being colorized

108 Views Asked by At

The following approach gets close to the result Format string output to JSON, but one issue is the "color_messsage" field which leads to special color characters to be part of the json logs

{"message": "Finished server process [54894]", "color_message": "Finished server process [\u001b[36m%d\u001b[0m]"}

Any recommended way to either drop the "color_message". An option could be to subclass the pythonjsonlogger.jsonlogger.JsonFormatter and pop the color messages but this seems a bit hacky.

Any recommendation?

Tried the same setup as here but with uvicorn only: Format string output to JSON

I also tried setting the --no-use-colors but as the documentation mentions (https://www.uvicorn.org/settings/#logging) this option is not set when we specify a logging config file.

0

There are 0 best solutions below