Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17069 -- Added log filter example to docs.

Added an example of filtering admin error emails (to exclude
UnreadablePostErrors) to the docs.
  • Loading branch information...
commit 32ffcb21a00e08eb478cc287bc3254ee765d815d 1 parent ab2f65b
mjjohnson authored

Showing 1 changed file with 29 additions and 0 deletions. Show diff stats Hide diff stats

  1. 29  docs/topics/logging.txt
29  docs/topics/logging.txt
@@ -516,6 +516,35 @@ logging module.
516 516
    through the filter. Handling of that record will not proceed if the callback
517 517
    returns False.
518 518
 
  519
+   For instance, to filter out :class:`~django.http.UnreadablePostError`
  520
+   (raised when a user cancels an upload) from the admin emails, you would
  521
+   create a filter function::
  522
+
  523
+    from django.http import UnreadablePostError
  524
+
  525
+    def skip_unreadable_post(record):
  526
+        if record.exc_info:
  527
+            exc_type, exc_value = record.exc_info[:2]
  528
+            if isinstance(exc_value, UnreadablePostError):
  529
+                return False
  530
+        return True
  531
+
  532
+   and then add it to your logging config::
  533
+
  534
+        'filters': {
  535
+            'skip_unreadable_posts': {
  536
+                '()': 'django.utils.log.CallbackFilter',
  537
+                'callback': skip_unreadable_post,
  538
+            }
  539
+        },
  540
+        'handlers': {
  541
+            'mail_admins': {
  542
+                'level': 'ERROR',
  543
+                'filters': ['skip_unreadable_posts'],
  544
+                'class': 'django.utils.log.AdminEmailHandler'
  545
+            }
  546
+        },
  547
+
519 548
 .. class:: RequireDebugFalse()
520 549
 
521 550
    .. versionadded:: 1.4

0 notes on commit 32ffcb2

Please sign in to comment.
Something went wrong with that request. Please try again.