nickjj / docker-django-example

A production ready example Django app that's using Docker and Docker Compose.
MIT License
1.17k stars 249 forks source link

Add `LOG_LEVEL` env var? #41

Open SHxKM opened 7 months ago

SHxKM commented 7 months ago

Really enjoying the quality of this, I was wondering if it'd be handy to have a LOG_LEVEL env var (detached from DEBUG) that would allow Django to output logs when running with gunicorn in production.

nickjj commented 7 months ago

Thanks.

Gunicorn is also used in development. There's a Gunicorn loglevel config option you can add that could be associated with a WEB_LOG_LEVEL env var that we add. Is that what you were thinking? Alternatively there's https://docs.djangoproject.com/en/5.0/topics/logging.

SHxKM commented 7 months ago

Just realized what I was really referring to is having Django log level be controlled by an environment variable.

nickjj commented 7 months ago

Django has different log levels for different components of its framework. For example here's the default logging settings: https://docs.djangoproject.com/en/5.0/ref/logging/#default-logging-configuration

We would have to override those and reference an env variable. Likely the handlers.console and loggers.django sections would be overwritten. The rest can remain hard coded because this project doesn't use the django.server and having admin emails only report errors is a good default for now.