Mik*_*maa 5 django sentry raven
我想在 Django 1.7 中将404 Not Found错误代码记录到 Sentry。
Django 提供了哪些钩子以便我可以推送logger.error()这些消息?
还有其他想法如何使用 Django 和 Sentry 监控非 500 个缺失/行为异常的页面吗?
查看Django Sentry 文档的报告其他状态代码部分:
如果你想向 Sentry 报告 404 Not Found 以及除了未捕获的异常(500 Internal Server Error)之外的其他错误,你需要为这些状态代码编写自己的 Django 视图。例如:
# in the root URL conf urls.py
handler404 = 'myapp.views.my_custom_page_not_found_view'
# myapp/views.py
from django.http import HttpResponseNotFound
from sentry_sdk import capture_message
def my_custom_page_not_found_view(*args, **kwargs):
capture_message("Page not found!", level="error")
# return any response here, e.g.:
return HttpResponseNotFound("Not found")
Run Code Online (Sandbox Code Playgroud)
有关自定义错误的更多信息,请阅读相关的 Django 文档
| 归档时间: |
|
| 查看次数: |
3507 次 |
| 最近记录: |