我有一个 django 1.4.2 应用程序日志记录到一个旋转文件。在我的 settings.py 中,我有:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
},
},
'handlers': {
'default': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': '/var/www/html/logs/mylog.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
'request_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': '/var/www/html/logs/django_request.log',
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
},
'loggers': {
'': {
'handlers': ['default'],
'level': 'ERROR',
'propagate': True
},
'django.request': { # Stop SQL debug from logging to main logger
'handlers': ['request_handler'],
'level': 'DEBUG',
'propagate': False
},
}
}
所以在日志目录中我看到了文件:
mc.log
mc.log.1
mc.log.2
mc.log.3
mc.log.4
mc.log.5
当 mc.log 达到 5M 时,文件已正确轮换,但新的 mc.log 是使用所有权 root.root 创建的。由于 apache 在 apache 用户下运行,它无法再访问文件并且应用程序停止工作。知道为什么使用 root.root 所有权而不是 apache.apache 创建新日志吗?
谢谢