Vingtoft Vingtoft - 15 days ago 6
Python Question

Django "./manage.py runserver" log to file instead of console

Running

python manage.py runserver
will initiate Django's development server and all logs are printed to the console.

I need to write the logs in a
django.log
file instead of console.

Django logging documentation is good, but I cant seem to configure the logging to log the same as
python manage.py runserver
.

Question: How can I log everything from
./manage.py runserver
to a file?

Answer

It is a simple linux redirect, so it should look something like this:

python manage.py runserver 0.0.0.0:8080 >> log.log 2>&1

Please note that I've set 8080 as the local port, you should change it according your project.

PS: This method (manage runserver) should be used for development only, not for deployment.