1

I have a Python Django app where we need to log using below code snippet to allow ELK to index the log record as JSON

logger.info(json.dumps({'level':'INFO','data':'some random data'})

I have to use json.dumps() everytime . Is there a way in logging module to get rid of json.dumps() in every log message but still achieve the same functionality

jebaseelan ravi
  • 185
  • 2
  • 10
  • 1
    Does this answer your question? [Python logging into file as a dictionary or JSON](https://stackoverflow.com/questions/50144628/python-logging-into-file-as-a-dictionary-or-json) – NicoCaldo May 31 '22 at 11:53

1 Answers1

1

python-json-logger do the job.

this article seems explain the approach to the solution.

You can customize the formatter, as suggested by @NicoCaldo

or in general use any other format like a 'pipe separated format' to communicate to ELK like inthis example

Glauco
  • 1,385
  • 2
  • 10
  • 20