Reputation: 73
I am trying to set up my Django project with uWSGI. I have defined my log handlers in settings.py
and they will write logs fine when I used the development server. However when I move to my production server using uWSGI, although the log file is created, it is empty.
My settings.py
contains this:
import logging
logger = logging.getLogger('django_auth_ldap')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/tmp/zdebug.log',
},
},
'loggers': {
'django': {
'handlers': ['console','file'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'devices': {
'handlers': ['console','file'],
'level': 'INFO'
},
'stack_configs': {
'handlers': ['console','file'],
'level': 'INFO'
},
'django_auth_ldap': {
'handlers': ['console','file'],
'level': 'INFO'
},
},
}
Thanks in advance for any help you can offer.
Upvotes: 3
Views: 838
Reputation: 8467
This is because your config is wrong. You've put loggers
inside handlers
, which violates the LOGGING
structure. It should have the handlers
, loggers
, filters
and formatters
at the same level of a dict indentation:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/tmp/zdebug.log',
},
},
'loggers': {
'django': {
'handlers': ['console','file'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
'devices': {
'handlers': ['console','file'],
'level': 'INFO'
},
'stack_configs': {
'handlers': ['console','file'],
'level': 'INFO'
},
'django_auth_ldap': {
'handlers': ['console','file'],
'level': 'INFO'
},
},
}
The empty file you see is created on Django boot, and Django logs on your development server because it uses default loggers, disregarding malformed config.
Upvotes: 2