有没有办法使用Django日志记录过滤特定的错误消息?例如不可压缩的fileerror

发布于 2025-02-08 06:20:53 字数 80 浏览 1 评论 0原文

有没有办法使用Django日志记录过滤特定的错误消息?例如,无法压缩的FileError

希望停止将这些错误发送到Sentry.io

Is there a way to filter out specific error messages using Django Logging? eg UncompressableFileError

Would like to stop these errors being sent to Sentry.io

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

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

发布评论

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

评论(2

梦过后 2025-02-15 06:20:53

您可以在Sentry处理程序上设置过滤器,该操作人员检查要过滤出来的错误类型,然后返回false将其丢弃。粗略:

def sentry_filter(record):
    return 'UncompressableFileError' not in record.getMessage()

然后

sentry_handler.addFilter(sentry_filter)

可能需要根据字符串的发生位置进行调整 -

You can set a Filter on the Sentry handler which checks for the type of errors you want to filter out, and return False to drop them. Roughly:

def sentry_filter(record):
    return 'UncompressableFileError' not in record.getMessage()

and then

sentry_handler.addFilter(sentry_filter)

This might need to be tweaked depending on where the string occurs - e.g. in message or traceback

兮颜 2025-02-15 06:20:53

最终从SA上的另一个答案中找到了这一点,该答案与Raven合作:

有没有一种方法可以使用Django日志记录过滤特定的错误消息?例如,不可压制的fileerror

class MyExceptionType(Exception):
    def __init__(self, message):
        super(MyExceptionType, self).__init__(message)

app = Flask(__name__)
app.config['SENTRY_CONFIG'] = {
    'ignore_exceptions': [MyExceptionType],
}

Found this in the end from another answer on SA which works with Raven:

Is there a way to filter out specific error messages using Django Logging? eg UncompressableFileError

class MyExceptionType(Exception):
    def __init__(self, message):
        super(MyExceptionType, self).__init__(message)

app = Flask(__name__)
app.config['SENTRY_CONFIG'] = {
    'ignore_exceptions': [MyExceptionType],
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文