[Django]-How do I write logs to docker container in a Django project?

2👍

Maybe add this command in you docker-compose to fire at startup.

docker logs --tail 1000 -f 'your_container_id_here'

1👍

You did everything right in Django to make your logs visible in docker logs. The only thing that I spotted is that you propagate such logs to the higher-level handler (e.g. gunicorn). You have two options:

The first option is to avoid propagation by setting propagate to False:

    'loggers': {
        '': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False,
        }
    },

The other option is to configure your application server to avoid filtering, but this will depend on the configuration of your app server.

Leave a comment