And*_*ndy 68
日志在您的settings.py文件中设置.一个新的默认项目如下所示:
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,这些不会创建日志文件.如果你想要那些,你需要添加一个filename参数handlers
'applogfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': os.path.join(DJANGO_ROOT, 'APPNAME.log'),
'maxBytes': 1024*1024*15, # 15MB
'backupCount': 10,
},
Run Code Online (Sandbox Code Playgroud)
这将设置一个旋转日志,可以获得15 MB的大小,并保留10个历史版本.
在loggers上面的部分中,您需要添加applogfile到handlers您的应用程序中
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'APPNAME': {
'handlers': ['applogfile',],
'level': 'DEBUG',
},
}
Run Code Online (Sandbox Code Playgroud)
此示例将您的日志放入Django根目录中的文件中 APPNAME.log
小智 22
添加到您的settings.py:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'debug.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
Run Code Online (Sandbox Code Playgroud)
它将创建一个debug.log在您的根目录中调用的文件.
https://docs.djangoproject.com/en/1.10/topics/logging/
slu*_*pet 11
设置https://docs.djangoproject.com/en/dev/topics/logging/然后这些错误将回显你指向它们的地方.默认情况下,它们往往会在杂草中消失,所以我总是先从一个好的日志记录设置开始.
以下是基本设置的一个非常好的示例:https: //ian.pizza/b/2013/04/16/getting-started-with-django-logging-in-5-minutes/
编辑:新链接移至:https://github.com/ianalexander/ianalexander/blob/master/content/blog/getting-started-with-django-logging-in-5-minutes.html
| 归档时间: |
|
| 查看次数: |
79535 次 |
| 最近记录: |