Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fc082caf
Commit
fc082caf
authored
Oct 19, 2010
by
Vinay Sajip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logging: Documented usage of callables as filters.
parent
435d306a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
12 deletions
+16
-12
Doc/library/logging.rst
Doc/library/logging.rst
+15
-6
Lib/logging/__init__.py
Lib/logging/__init__.py
+1
-6
No files found.
Doc/library/logging.rst
View file @
fc082caf
...
...
@@ -3040,12 +3040,12 @@ Currently, the useful mapping keys in a :class:`LogRecord` are:
Filter Objects
--------------
:class:`Filter`\ s can be used by :class:`Handler`\ s and :class:`Logger`\ s for
more sophisticated filtering than is provided by levels. The base filter clas
s
only allows events which are below a certain point in the logger hierarchy. Fo
r
example, a filter initialized with "A.B" will allow events logged by loggers
"A.B
", "A.B.C", "A.B.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If
initialized with the
empty string, all events are passed.
``Filters` can be used by ``Handlers`` and ``Loggers`` for more sophisticated
filtering than is provided by levels. The base filter class only allows event
s
which are below a certain point in the logger hierarchy. For example, a filte
r
initialized with "A.B" will allow events logged by loggers "A.B", "A.B.C",
"A.B
.C.D", "A.B.D" etc. but not "A.BB", "B.A.B" etc. If initialized with the
empty string, all events are passed.
.. class:: Filter(name='')
...
...
@@ -3068,6 +3068,15 @@ etc.) This means that events which have been generated by descendant loggers
will not be filtered by a logger'
s
filter
setting
,
unless
the
filter
has
also
been
applied
to
those
descendant
loggers
.
..
versionchanged
::
3.2
You
don
't need to create specialized ``Filter`` classes: you can use a plain
function (or other callable) as a filter. The filtering logic will check to
see if the filter object has a ``filter`` attribute: if it does, it'
s
assumed
to
be
a
``
Filter
``
and
its
:
meth
:`~
Filter
.
filter
`
method
is
called
.
Otherwise
,
it
's assumed to be a callable and called with the record as the single
parameter. The result should conform to that of :meth:`~Filter.filter`.
Other uses for filters
^^^^^^^^^^^^^^^^^^^^^^
...
...
Lib/logging/__init__.py
View file @
fc082caf
...
...
@@ -613,13 +613,8 @@ class Filterer(object):
for
f
in
self
.
filters
:
if
hasattr
(
f
,
'filter'
):
result
=
f
.
filter
(
record
)
elif
hasattr
(
f
,
'__call__'
):
try
:
result
=
f
(
record
)
except
Exception
:
result
=
True
# filter failed, assume a pass
else
:
result
=
False
# we don't know what f is
result
=
f
(
record
)
# assume callable - will raise if not
if
not
result
:
rv
=
0
break
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment