【发布时间】:2025-12-12 07:05:01
【问题描述】:
如果我不包括日志记录,我有一个带有 Celery 的 Django 应用程序,使用 AWS SQS 在 ElasticBeanstalk 上运行良好。
当我使用“logging.FileHandler”包含日志记录时,celery 会出现 permission denied 错误,因为它没有我的日志文件的权限。这是我的错误
ValueError:无法配置处理程序“celery_file”:[Errno 13] 权限被拒绝:'/opt/python/log/django.log'
这是我的日志记录设置
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler'
},
'file': {
'level': log_level,
'class': 'logging.FileHandler',
#'filters': ['require_debug_false'],
'filename': os.environ.get('LOG_FILE_PATH', LOG_FILE_PATH + '/var/log/django.log')
},
'mail_admins': {
'level': 'ERROR',
#'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'cqc_file' :{
'level': log_level,
'class': 'logging.FileHandler',
#'filters': ['require_debug_false'],
'filename': os.environ.get('LOG_FILE_PATH', LOG_FILE_PATH + '/var/log/cqc.log')
},
'null': {
'class': 'logging.NullHandler',
},
'celery_file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': os.environ.get('LOG_FILE_PATH', LOG_FILE_PATH + '/var/log/celery.log'),
}
},
'loggers': {
'': {
'level': 'WARNING',
'handlers': ['file'],
},
'debug' : {
'level': log_level,
'handlers': ['file'],
},
'django.security.DisallowedHost': {
'handlers': ['null'],
'level' : 'CRITICAL',
'propagate': False,
},
'django.request': {
'handlers': ['file','mail_admins'],
'level': 'DEBUG',
'propagate': True,
},
'cqc_report' : {
'level' : 'INFO',
'handlers' : ['cqc_file']
},
'celery.task' : {
'handlers': ['console', 'celery_file'],
'level': 'INFO',
'propagate': True,
}
}
}
我想我需要通过弹性 beanstalk 容器命令让 celery 访问 django.log、celery.log 和 cqc.log 文件。我厌倦了使用:
03_change_permissions:
command: chmod g+s /opt/python/log
04_change_owner:
command: chown root:wsgi /opt/python/log
05_add_celery_to_wsgi:
command: usermod -a -G wsgi celery
但这只是给了我一个错误,说没有用户芹菜(或类似的东西)。
如何让文件日志记录工作?
【问题讨论】:
标签: django amazon-elastic-beanstalk django-celery