[英]Django uWSGI creates log file but the file is empty (works with development server)
我正在尝试用uWSGI设置我的Django项目。 我在settings.py
定义了我的日志处理程序,当我使用开发服务器时,它们会写日志。 但是,当我使用uWSGI移动到我的生产服务器时,虽然创建了日志文件,但它是空的。
我的settings.py
包含:
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'
},
},
}
提前感谢您提供的任何帮助。
这是因为您的配置错误。 您已将loggers
放在handlers
,这违反了LOGGING
结构。 它应该在dict缩进的同一级别具有handlers
, loggers
, filters
和formatters
:
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'
},
},
}
您看到的空文件是在Django启动时创建的,Django会在您的开发服务器上登录,因为它使用默认记录器,而忽略了格式错误的配置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.