[Django]-Django – Rotating File Handler stuck when file is equal to maxBytes

23πŸ‘

βœ…

I guess you are facing the problem described in this post: Django logging with RotatingFileHandler error

That is, when running Django development server, actually there are two processes running.

by default, two processes of Django servers are running. One is the
actual server, while the other is to detect changes in the code and
reload the server. Therefore, settings.py is imported twice, and
consequently the two processes are accessing the log file at the same
time.

As advised there, try

python manage.py runserver --noreload
πŸ‘€jalopaba

15πŸ‘

As describe in other answers python manage.py runserver --noreload will work. But here’s another solution that still works with code reload.

Add this at the end of your settings.py

if DEBUG and os.environ.get('RUN_MAIN', None) != 'true':
    LOGGING = {}

python manage.py runserver starts a python process that launches your server in a child python process. Each time the parent detects a change it recreates a new child. The problem is that the log rotation by the child process fails because the parent still has a handle on that file. This solution tells the parent that there are no log file.

πŸ‘€user3748764

Leave a comment