How to Open Django Error Log File (And Configure)

The log files for your Django application are defined in the settings.py file. Let's begin by opening the settings.py file which is located in your project's main directory.

 

nano src/myproject/settings.py

 

Now look for a dictionary called LOGGING. If it isn't in the file, add the following code somewhere appropriate in your settings.py file:

 

src/myproject/settings.py
LOGGING = {
   'version': 1,
   'disable_existing_loggers': False,
   'handlers': {
       'file': {
           'level': 'DEBUG',
           'class': 'logging.FileHandler',
           'filename': 'debug.log',
       },
   },
   'loggers': {
       'django': {
           'handlers': ['file'],
           'level': 'DEBUG',
           'propagate': True,
       },
   },
}

 

This will create a file called debug.log in the project directory when an error occurs.

 

If this doesn't work you may need to reload the daemon service and possibly the Web Server Gateway Interface if you are using one. For me the WSGI is Gunicorn.

 

sudo systemctl daemon-reload
sudo systemctl restart gunicorn

 

Now you can open the log file with nano:

 

nano src/debug.log