我有项目(Django = 1.9.7)和芹菜,项目结构就是这样
myproject
-- manage.py
-- myproject
-- config
-- config.py
-- logging_config.py
-- celery_config.py
-- settings.py
-- app_1
-- models.py
-- tasks.py
-- views.py
-- app_N
-- models.py
-- tasks.py
-- views.py
```
import os
from .config import LOG_FILE, REQUEST_LOG_FILE, LOGGING_LEVEL
# print LOG_FILE, REQUEST_LOG_FILE
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'django': {
'format': 'django %(asctime)s [%(levelname)s/process_id=%(process)d/(%(thread)d)] %(name)s : %(message)s'
},
'general': {
'format': 'general %(asctime)s [%(levelname)s/process_id=%(process)d/(%(thread)d)] %(name)s : %(message)s'
},
'celery': {
'format': 'celery %(asctime)s [%(levelname)s/process_id=%(process)d/(%(thread)d)] %(name)s : %(message)s'
},
'request': {
'format': 'request %(asctime)s [%(levelname)s/process_id=%(process)d/(%(thread)d)] %(name)s : %(message)s'
},
'console': {
'format': 'console %(asctime)s [%(levelname)s/process_id=%(process)d/(%(thread)d)] %(name)s : %(message)s'
},
},
'filters': {
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
},
},
'handlers': {
'django': {
'level': LOGGING_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'filename': '{file}'.format(file=LOG_FILE),
'maxBytes': 1024 * 1024 * 100, # 100 MB
'backupCount': 5,
'formatter': 'django',
},
'general': {
'level': LOGGING_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'filename': '{file}'.format(file=LOG_FILE),
'maxBytes': 1024 * 1024 * 100, # 100 MB
'backupCount': 5,
'formatter': 'general',
},
'requests': {
'level': LOGGING_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'filename': '{file}'.format(file=REQUEST_LOG_FILE),
'maxBytes': 1024 * 1024 * 100, # 100 MB
'backupCount': 5,
'formatter': 'request',
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': False,
},
'celery.tasks': {
'level': LOGGING_LEVEL,
'class': 'logging.handlers.RotatingFileHandler',
'filename': '{file}'.format(file=LOG_FILE),
'maxBytes': 1024 * 1024 * 100, # 100 MB
'backupCount': 5,
'formatter': 'celery',
},
'console': {
'level': LOGGING_LEVEL,
'class': 'logging.StreamHandler',
'formatter': 'console',
# 'filters': ['require_debug_true'],
},
},
'loggers': {
'': {
'handlers': ['mail_admins', 'general'],
'level': LOGGING_LEVEL,
'propagate': False,
},
'django.request': {
'handlers': ['mail_admins', 'requests'],
'level': LOGGING_LEVEL,
'propagate': False,
},
'celery.tasks': {
'handlers': ['mail_admins','celery.tasks'],
'level': LOGGING_LEVEL,
'propagate': False,
},
'django': {
'handlers': ['mail_admins', 'django'],
'level': LOGGING_LEVEL,
'propagate': True
},
}
}
```
注意: LOGGING_LEVEL ='调试'
日志配置在本地服务器中完美运行..所有日志都设置为相应的文件,
但在PROD上它失败..只有django
记录器可以工作,但其余记录器不能打印到相应的文件
任何人都可以提供帮助..因为我无法确定我做错了什么?
修改 需要注意的一点是我通过邮件正确地收到错误消息,我没有得到的是相应文件中的调试或信息消息。除了django记录器中的所有日志,celerytask的所有日志,任何应用程序都缺失