当 Debug = True 时 Django 错误报告电子邮件

发布于 2024-11-16 21:46:56 字数 130 浏览 5 评论 0原文

有没有办法让 Django 通过电子邮件向我发送错误报告,即使我将调试设置为 True?

我在文档中没有看到任何内容。

编辑:

如果重要的话,我正在使用 Django 1.2。 不,这不是生产系统。

Is there a way to get Django to email me error reports even though I have debug set to True?

I didn't see anything in the docs.

Edit:

I'm on Django 1.2 if it matters.
No, this isn't a production system.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

沉默的熊 2024-11-23 21:46:56

如果您只有一封电子邮件,请确保列表中有逗号:

ADMINS = (('Admin', '[email protected]'),)

我尝试了这些并且似乎有效:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}

If you only have one email, make sure you have a comma in the list:

ADMINS = (('Admin', '[email protected]'),)

I tried these and seems work:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'class': 'django.utils.log.AdminEmailHandler'
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins'],
            'level': 'ERROR',
            'propagate': True,
        },
    }
}
夜清冷一曲。 2024-11-23 21:46:56

您可能想查看 django-sentry。它确实是为在生产中使用而设计的,但它具有 TESTING 设置,使其在 DEBUG=True 时也能工作。它实际上也可能在那时发送电子邮件——我自己还没有测试过,但它至少会保留错误日志,您可以随时从任何支持网络的设备查看。

此外,当您最终投入生产时,它将成为您的救星。

You might want to look at django-sentry. It's really designed for use in production, but it has TESTING setting to make it work when DEBUG=True as well. It might actually send out emails at that point, too -- haven't tested that myself, but it'll at least keep a log of errors that you can view at any time from any web-enabled device.

Besides, when you do eventually go to production, it'll be a life-saver.

幸福还没到 2024-11-23 21:46:56

只是为了稍微扩展一下 Bob Roberts 的答案,我在 django.utils.log 中找到了默认的日志配置。您只需将其复制并粘贴到您的设置中,将其命名为 LOGGING,然后更改行:

# settings.py:
# copied from django.utils.log import DEFAULT_LOGGING
LOGGING = {
    ...
        'mail_admins': {
            'level': 'ERROR',
            # emails for all errors
            #'filters': ['require_debug_false'],
            'filters': [],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    ...
}

Just to expand on Bob Roberts answer a bit, I found the default logging configuration in django.utils.log. You can just copy and paste it to your settings, name it LOGGING, and change the line:

# settings.py:
# copied from django.utils.log import DEFAULT_LOGGING
LOGGING = {
    ...
        'mail_admins': {
            'level': 'ERROR',
            # emails for all errors
            #'filters': ['require_debug_false'],
            'filters': [],
            'class': 'django.utils.log.AdminEmailHandler'
        }
    ...
}
锦欢 2024-11-23 21:46:56

我相信您可以通过为与 settings.py 中定义的 AdminEmailHandler 关联的过滤器指定一个空列表来实现这一点。

例如:

'mail_admins': {
    'level': 'ERROR',
    'class': 'django.utils.log.AdminEmailHandler',
    'filters': []
}

默认情况下,此类的过滤器是 django.utils.log.RequireDebugFalse。

I believe you can achieve that by specifying an empty list to the filters associated with your AdminEmailHandler defined in your settings.py.

For instance:

'mail_admins': {
    'level': 'ERROR',
    'class': 'django.utils.log.AdminEmailHandler',
    'filters': []
}

By default the filters for this class would be a django.utils.log.RequireDebugFalse.

巷子口的你 2024-11-23 21:46:56

将以下行添加到您的 settings.py 文件中应该可以解决问题。

LOGGING['handlers']['mail_admins']['filters'] = []

Adding the following line to your settings.py file should do the trick.

LOGGING['handlers']['mail_admins']['filters'] = []
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文