Usefull commands : python / python3 json.tools

Viewing the log statements in Logstash

Django logging configuration

Logging is done mainly by configuring the Docker hosting Django to ship via UDP (same machine) the log statements.

sudo docker run               \
   -d                         \
   --network djangoNetwork    \
   --log-driver gelf --log-opt gelf-address=udp://<ip>:port \
   --log-opt tag=ITNDjango    \
   --name ITNDjango           \
   itndjango

Viewing the logs is pretty awfull

tail -f   /var/log/logstash/tls-All-Series/ITNDjango-2021-03-21.log  
{"image_name":"itndjango","image_id":"sha256:f390481f05a37970d29e52bafea81bc7f634d69b7d0cff6adc6491493cfb1101","@version":"1","message":"def handler500(request)::invoked. Request = <WSGIRequest: GET '/en/Schedule/'>","host":"tls-All-Series","@timestamp":"2021-03-21T15:34:45.163Z","version":"1.1","level":3,"container_name":"ITNDjango","source_host":"172.42.0.1","tag":"ITNDjango","container_id":"45331982c3ac6ea18671b04ef45cdb223ed268c381c4bc1d9766e2deb2509125","command":"gunicorn -b 0.0.0.0:8000 wsgi:application","created":"2021-03-21T15:28:42.53984554Z"}
{"image_name":"itndjango","image_id":"sha256:f390481f05a37970d29e52bafea81bc7f634d69b7d0cff6adc6491493cfb1101","@version":"1","message":"\r// BODY : b''","host":"tls-All-Series","@timestamp":"2021-03-21T15:34:45.164Z","version":"1.1","level":3,"container_name":"ITNDjango","source_host":"172.42.0.1","tag":"ITNDjango","container_id":"45331982c3ac6ea18671b04ef45cdb223ed268c381c4bc1d9766e2deb2509125","command":"gunicorn -b 0.0.0.0:8000 wsgi:application","created":"2021-03-21T15:28:42.53984554Z"}
{"image_name":"itndjango","image_id":"sha256:f390481f05a37970d29e52bafea81bc7f634d69b7d0cff6adc6491493cfb1101","@version":"1","message":"\r// Encoding : GET","host":"tls-All-Series","@timestamp":"2021-03-21T15:34:45.175Z","version":"1.1","level":3,"container_name":"ITNDjango","source_host":"172.42.0.1","tag":"ITNDjango","container_id":"45331982c3ac6ea18671b04ef45cdb223ed268c381c4bc1d9766e2deb2509125","command":"gunicorn -b 0.0.0.0:8000 wsgi:application","created":"2021-03-21T15:28:42.53984554Z"}
{"image_name":"itndjango","image_id":"sha256:f390481f05a37970d29e52bafea81bc7f634d69b7d0cff6adc6491493cfb1101","@version":"1","message":"\r ","host":"tls-All-Series","@timestamp":"2021-03-21T15:34:45.176Z","version":"1.1","level":3,"container_name":"ITNDjango","source_host":"172.42.0.1","tag":"ITNDjango","container_id":"45331982c3ac6ea18671b04ef45cdb223ed268c381c4bc1d9766e2deb2509125","command":"gunicorn -b 0.0.0.0:8000 wsgi:application","created":"2021-03-21T15:28:42.53984554Z"}
{"image_name":"itndjango","image_id":"sha256:f390481f05a37970d29e52bafea81bc7f634d69b7d0cff6adc6491493cfb1101","@version":"1","message":"ERROR : ************************************************* ","host":"tls-All-Series","@timestamp":"2021-03-21T15:34:45.164Z","version":"1.1","level":3,"container_name":"ITNDjango","source_host":"172.42.0.1","tag":"ITNDjango","container_id":"45331982c3ac6ea18671b04ef45cdb223ed268c381c4bc1d9766e2deb2509125","command":"gunicorn -b 0.0.0.0:8000 wsgi:application","created":"2021-03-21T15:28:42.53984554Z"}

but what anyone wanted is something pretty

{
    "image_name": "itndjango",
    "image_id": "sha256:4708851a84b1546def07a605e99df236736a128e0b7d930538c5baf9634d5d9d",
    "@version": "1",
    "message": "%get  229.92563247680664 ms",
    "host": "tls-All-Series",
    "@timestamp": "2021-03-21T20:57:58.070Z",
    "version": "1.1",
    "level": 3,
    "container_name": "ITNDjango",
    "source_host": "172.42.0.1",
    "tag": "ITNDjango",
    "container_id": "109cda51786fc63c60dc9df7986255a2a006ecd26ed655b3e7bffaf800e31f85",
    "command": "gunicorn -b 0.0.0.0:8000 wsgi:application",
    "created": "2021-03-21T20:55:41.980447633Z"
}

Hopefully Python has some build in tools

tail -n 200 -f    /var/log/logstash/<node>/ITNDjango-2021-03-21.log  \
 | python3  -m json.tool  --json-lines 

Reference

[1] Python3 json tool reference