-
-
Couldn't load subscription status.
- Fork 33.2k
gh-92592: Allow logging filters to return a LogRecord. (GH-92591) #92591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
3aeeba6 1e4d27f b526a35 f1ea183 19561d3 14e704d 4d34540 a69e76a 67453f6 b1e1084 f72c594 225329f 735d78a 5e54c77 f52e404 46e2f7f 7a0f470 643551d File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| | @@ -662,9 +662,10 @@ empty string, all events are passed. | |
| | ||
| .. method:: filter(record) | ||
| | ||
| Is the specified record to be logged? Returns zero for no, nonzero for | ||
| yes. If deemed appropriate, the record may be modified in-place by this | ||
| method. | ||
| Is the specified record to be logged? Returns falsy for no, truthy for | ||
| yes. Filters can either modify log records in-place or return a completely | ||
| different record instance which will replace the original | ||
| log record without modifying it. | ||
| ||
| | ||
| Note that filters attached to handlers are consulted before an event is | ||
| emitted by the handler, whereas filters attached to loggers are consulted | ||
| | @@ -686,6 +687,12 @@ which has a ``filter`` method with the same semantics. | |
| parameter. The returned value should conform to that returned by | ||
| :meth:`~Filter.filter`. | ||
| | ||
| .. versionchanged:: 3.12 | ||
| You can now return a :class:`LogRecord` instance from filters to replace | ||
| the log record without modifying it in place. This allows filters attached to | ||
| ||
| on a :class:`Handler` to modify the log record before it is emitted without | ||
| ||
| having side effects on other handlers. | ||
| | ||
| Although filters are used primarily to filter records based on more | ||
| sophisticated criteria than levels, they get to see every record which is | ||
| processed by the handler or logger they're attached to: this can be useful if | ||
| | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Let :mod:`logging` filters to return a :class:`logging.LogRecord` instance | ||
| ||
| so that filters attached to :class:`logging.Handler`\ s can enrich records without | ||
| side effects on other handlers. | ||
Uh oh!
There was an error while loading. Please reload this page.