django / daphne

Django Channels HTTP/WebSocket server
BSD 3-Clause "New" or "Revised" License
2.32k stars 256 forks source link

Added argument to change log format #414

Closed abhi1693 closed 2 years ago

abhi1693 commented 2 years ago

The current log-format is hardcoded into the application, which causes issues with my JSON log parsers as the format written to the stdout/stderr is not JSON.

Current Behavior

2022-04-08 15:50:42,351 INFO     {'request_id': '814cee1c-7a72-492d-b630-340afb0d76ea', 'user_id': None, 'ip': '65.49.36.22', 'request': 'GET /health/ping/', 'user_agent': 'kube-probe/1.20', 'event': 'request_started', 'timestamp': '2022-04-08T15:50:42.350996Z', 'logger': 'django_structlog.middlewares.request', 'level': 'info'}

The logline gets appended with DateTime and log level outside the scope of my JSON which is not desirable for me.

I have added a simple CLI argument that can be overridden to pass custom formats which are then written to the destination. The argument still keeps the current implementation intact and allows a user to change the format.

abhi1693 commented 2 years ago

I have updated the change log

carltongibson commented 2 years ago

Merged in 87bc5a7975e3e77ec64a183058b6e875cf744cf4. Thanks @abhi1693