Search code examples
pythondjangologgingfiltersentry

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


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


Solution

  • 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