I have been following the Django Logging docs but haven't been able to produce logs. All of this is within a virtualenv.
My views.py file contains
import logging
logger = logging.getLogger(__name__)
def index(request):
logger.debug('Index page')
return render(request, 'app/index.html')
In settings.py I have:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/pathtologfile/debug.log',
},
},
'loggers': {
'': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
No logs are appearing in the log file from views.py when I navigate to the index page.
However, if I use the django shell to execute the following commands the log will show up in the log file:
>>>import logging
>>>logger = logging.getLogger(__name__)
>>>logger.debug('shell')
How can I get logs from view.py (or any file for that matter)?
I have tried the following with no result:
- Ensured log levels are all set to debug
- Tried naming logger 'root' or ''
- Tried 'disable_existing_loggers': False and True
- Tried answers on https://stackguides.com/questions/tagged/django-logging
- Tried setting full write permission on the log file
Is there anything wrong with my settings? Any where to even start looking at to debug this?