Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
6dbed2e8
Kaydet (Commit)
6dbed2e8
authored
Eki 19, 2010
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
logging: Allowed filters to be just callables.
üst
6fac8171
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
1 deletion
+45
-1
__init__.py
Lib/logging/__init__.py
+14
-1
test_logging.py
Lib/test/test_logging.py
+29
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/logging/__init__.py
Dosyayı görüntüle @
6dbed2e8
...
@@ -604,10 +604,23 @@ class Filterer(object):
...
@@ -604,10 +604,23 @@ class Filterer(object):
The default is to allow the record to be logged; any filter can veto
The default is to allow the record to be logged; any filter can veto
this and the record is then dropped. Returns a zero value if a record
this and the record is then dropped. Returns a zero value if a record
is to be dropped, else non-zero.
is to be dropped, else non-zero.
.. versionchanged: 3.2
Allow filters to be just callables.
"""
"""
rv
=
1
rv
=
1
for
f
in
self
.
filters
:
for
f
in
self
.
filters
:
if
not
f
.
filter
(
record
):
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
if
not
result
:
rv
=
0
rv
=
0
break
break
return
rv
return
rv
...
...
Lib/test/test_logging.py
Dosyayı görüntüle @
6dbed2e8
...
@@ -309,6 +309,35 @@ class BasicFilterTest(BaseTest):
...
@@ -309,6 +309,35 @@ class BasicFilterTest(BaseTest):
finally
:
finally
:
handler
.
removeFilter
(
filter_
)
handler
.
removeFilter
(
filter_
)
def
test_callable_filter
(
self
):
# Only messages satisfying the specified criteria pass through the
# filter.
def
filterfunc
(
record
):
parts
=
record
.
name
.
split
(
'.'
)
prefix
=
'.'
.
join
(
parts
[:
2
])
return
prefix
==
'spam.eggs'
handler
=
self
.
root_logger
.
handlers
[
0
]
try
:
handler
.
addFilter
(
filterfunc
)
spam
=
logging
.
getLogger
(
"spam"
)
spam_eggs
=
logging
.
getLogger
(
"spam.eggs"
)
spam_eggs_fish
=
logging
.
getLogger
(
"spam.eggs.fish"
)
spam_bakedbeans
=
logging
.
getLogger
(
"spam.bakedbeans"
)
spam
.
info
(
self
.
next_message
())
spam_eggs
.
info
(
self
.
next_message
())
# Good.
spam_eggs_fish
.
info
(
self
.
next_message
())
# Good.
spam_bakedbeans
.
info
(
self
.
next_message
())
self
.
assert_log_lines
([
(
'spam.eggs'
,
'INFO'
,
'2'
),
(
'spam.eggs.fish'
,
'INFO'
,
'3'
),
])
finally
:
handler
.
removeFilter
(
filterfunc
)
#
#
# First, we define our levels. There can be as many as you want - the only
# First, we define our levels. There can be as many as you want - the only
...
...
Misc/NEWS
Dosyayı görüntüle @
6dbed2e8
...
@@ -34,6 +34,8 @@ Core and Builtins
...
@@ -34,6 +34,8 @@ Core and Builtins
Library
Library
-------
-------
- logging: Allowed filters to be just callables.
- logging: Added tests for _logRecordClass changes.
- logging: Added tests for _logRecordClass changes.
- Issue #10092: Properly reset locale in calendar.Locale*Calendar classes.
- Issue #10092: Properly reset locale in calendar.Locale*Calendar classes.
...
...
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