【发布时间】:2015-04-21 07:01:19
【问题描述】:
我已按照 django 网站 (https://docs.djangoproject.com/en/1.7/topics/logging/#examples) 的指示在我的 django 应用程序中添加了一些记录器,但无论出于何种原因,这些日志都没有应用这些格式。这是我的记录器设置:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(asctime)s : module %(name)s : %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
}
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'logging.NullHandler',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'file_request': {
'level': 'WARNING',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(file_root, 'request' , 'wilkins_request.log'),
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 0,
},
'file_backend': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filters': ['require_debug_true'],
'filename': os.path.join(file_root, 'backend' , 'wilkins_backend.log'),
'maxBytes': 1024*1024*6, # 6MB
'backupCount': 0,
},
'file_security': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(file_root, 'backend' , 'wilkins_security.log'),
'maxBytes': 1024*1024*6, # 6MB
'backupCount': 0,
},
'file_migrations': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.path.join(file_root, 'backend' , 'wilkins_migrations.log'),
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 0,
},
'file_debug': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filters': ['require_debug_true'],
'filename': os.path.join(file_root, 'debug' , 'wilkins.log'),
'filters': ['require_debug_true'],
'maxBytes': 1024*1024*1, # 1MB
'backupCount': 0,
},
},
'loggers': {
'django': {
'handlers': ['null'],
'propagate': True,
'level': 'INFO',
'formatter': 'simple'
},
'django.request': {
'handlers': ['file_request'],
'level': 'WARNING',
'propagate': True,
'formatter': 'simple'
},
'django.security': {
'handlers': ['file_security'],
'level': 'INFO',
'propagate': True,
'formatter': 'simple'
},
'django.db.backends': {
'handlers': ['file_backend'],
'level': 'DEBUG',
'propagate': False,
'formatter': 'simple'
},
'django.db.backends.schema': {
'handlers': ['file_migrations'],
'level': 'DEBUG',
'propagate': False,
'formatter': 'simple'
},
'wilkins': {
'handlers': ['file_debug'],
'level': 'DEBUG',
'propagate': True,
'formatter': 'simple'
},
}
}
但我的输出是这样的:
(来自 wilkins_request.log)
Not Found: /accounts/login9
Not Found: /accounts/login9
Not Found: /accounts/login9
Not Found: /l
Not Found: /l
Not Found: /l
Not Found: /favicon.ico
(来自 wilkins.log)
Made it to the Projects view.
Made it to the Projects view.
Made it to the Projects view.
Made it to the Projects view.
我完全不知道为什么会发生这种情况。我使用的是 Django 1.7,所以除了这个日志变量之外,我没有更改 django 中的任何代码路径或设置。
【问题讨论】: