用Django记录404页面未找到

时间:2022-10-04 19:19:05

I'd like to log 404 Not Found errors codes to Sentry in Django 1.7.

我想在Django 1.7中记录404未发现错误代码。

What hooks Django provides so I could push logger.error() message for these?

是什么挂钩Django提供的,这样我就可以将logger.error()消息推给它们?

Any other ideas how one should monitor non-500 missing / weirdly behaving pages with Django and Sentry?

还有什么办法可以让我们用Django和哨兵来监控非500丢失/行为怪异的页面吗?

2 个解决方案

#1


1  

Take a look at the docs for custom error handlers.

请查看文档中的自定义错误处理程序。

Basically I think you'll probably want to setup views for the errors you want to capture which can render templates you need or log messages etc; Customising error views. Obviously in those views you can access parts of the request object to collect any information you might need.

基本上,我认为你可能想要设置视图为你想要捕获的错误,可以呈现你需要的模板或记录消息等等;定制的错误观点。显然,在这些视图中,您可以访问request对象的某些部分,以收集您可能需要的任何信息。

#2


0  

Sentry has a middleware to log 404s automatically.

哨兵有一个自动记录404s的中间件。

# Use ``MIDDLEWARE_CLASSES`` prior to Django 1.10
MIDDLEWARE = (
    'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',
    ...,
) + MIDDLEWARE

See "404 Logging" in the Sentry Django documentation for more info including how to ignore 404s for certain paths.

有关更多信息,请参见哨兵Django文档中的“404日志记录”,其中包括如何为某些路径忽略404s。

#1


1  

Take a look at the docs for custom error handlers.

请查看文档中的自定义错误处理程序。

Basically I think you'll probably want to setup views for the errors you want to capture which can render templates you need or log messages etc; Customising error views. Obviously in those views you can access parts of the request object to collect any information you might need.

基本上,我认为你可能想要设置视图为你想要捕获的错误,可以呈现你需要的模板或记录消息等等;定制的错误观点。显然,在这些视图中,您可以访问request对象的某些部分,以收集您可能需要的任何信息。

#2


0  

Sentry has a middleware to log 404s automatically.

哨兵有一个自动记录404s的中间件。

# Use ``MIDDLEWARE_CLASSES`` prior to Django 1.10
MIDDLEWARE = (
    'raven.contrib.django.raven_compat.middleware.Sentry404CatchMiddleware',
    ...,
) + MIDDLEWARE

See "404 Logging" in the Sentry Django documentation for more info including how to ignore 404s for certain paths.

有关更多信息,请参见哨兵Django文档中的“404日志记录”,其中包括如何为某些路径忽略404s。