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
365701ad
Kaydet (Commit)
365701ad
authored
Şub 09, 2015
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added respect_handler_level to QueueListener.
üst
438f9134
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
6 deletions
+50
-6
logging-cookbook.rst
Doc/howto/logging-cookbook.rst
+9
-0
logging.handlers.rst
Doc/library/logging.handlers.rst
+9
-2
handlers.py
Lib/logging/handlers.py
+10
-4
test_logging.py
Lib/test/test_logging.py
+19
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/howto/logging-cookbook.rst
Dosyayı görüntüle @
365701ad
...
...
@@ -325,6 +325,15 @@ which, when run, will produce::
MainThread: Look out!
.. versionchanged:: 3.5
Prior to Python 3.5, the :class:`QueueListener` always passed every message
received from the queue to every handler it was initialized with. (This was
because it was assumed that level filtering was all done on the other side,
where the queue is filled.) From 3.5 onwards, this behaviour can be changed
by passing a keyword argument ``respect_handler_level=True`` to the
listener's constructor. When this is done, the listener compares the level
of each message with the handler's level, and only passes a message to a
handler if it's appropriate to do so.
.. _network-logging:
...
...
Doc/library/logging.handlers.rst
Dosyayı görüntüle @
365701ad
...
...
@@ -953,13 +953,20 @@ applications where threads servicing clients need to respond as quickly as
possible, while any potentially slow operations (such as sending an email via
:class:`SMTPHandler`) are done on a separate thread.
.. class:: QueueListener(queue, *handlers)
.. class:: QueueListener(queue, *handlers
, respect_handler_level=False
)
Returns a new instance of the :class:`QueueListener` class. The instance is
initialized with the queue to send messages to and a list of handlers which
will handle entries placed on the queue. The queue can be any queue-
like object; it's passed as-is to the :meth:`dequeue` method, which needs
to know how to get messages from it.
to know how to get messages from it. If ``respect_handler_level`` is ``True``,
a handler's level is respected (compared with the level for the message) when
deciding whether to pass messages to that handler; otherwise, the behaviour
is as in previous Python versions - to always pass each message to each
handler.
.. versionchanged:: 3.5
The ``respect_handler_levels`` argument was added.
.. method:: dequeue(block)
...
...
Lib/logging/handlers.py
Dosyayı görüntüle @
365701ad
# Copyright 2001-201
3
by Vinay Sajip. All Rights Reserved.
# Copyright 2001-201
5
by Vinay Sajip. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
...
...
@@ -18,7 +18,7 @@
Additional handlers for the logging package for Python. The core package is
based on PEP 282 and comments thereto in comp.lang.python.
Copyright (C) 2001-201
3
Vinay Sajip. All Rights Reserved.
Copyright (C) 2001-201
5
Vinay Sajip. All Rights Reserved.
To use, simply 'import logging.handlers' and log away!
"""
...
...
@@ -1350,7 +1350,7 @@ if threading:
"""
_sentinel
=
None
def
__init__
(
self
,
queue
,
*
handlers
):
def
__init__
(
self
,
queue
,
*
handlers
,
respect_handler_level
=
False
):
"""
Initialise an instance with the specified queue and
handlers.
...
...
@@ -1359,6 +1359,7 @@ if threading:
self
.
handlers
=
handlers
self
.
_stop
=
threading
.
Event
()
self
.
_thread
=
None
self
.
respect_handler_level
=
respect_handler_level
def
dequeue
(
self
,
block
):
"""
...
...
@@ -1399,7 +1400,12 @@ if threading:
"""
record
=
self
.
prepare
(
record
)
for
handler
in
self
.
handlers
:
handler
.
handle
(
record
)
if
not
self
.
respect_handler_level
:
process
=
True
else
:
process
=
record
.
levelno
>=
handler
.
level
if
process
:
handler
.
handle
(
record
)
def
_monitor
(
self
):
"""
...
...
Lib/test/test_logging.py
Dosyayı görüntüle @
365701ad
...
...
@@ -3006,6 +3006,25 @@ class QueueHandlerTest(BaseTest):
self
.
assertTrue
(
handler
.
matches
(
levelno
=
logging
.
WARNING
,
message
=
'1'
))
self
.
assertTrue
(
handler
.
matches
(
levelno
=
logging
.
ERROR
,
message
=
'2'
))
self
.
assertTrue
(
handler
.
matches
(
levelno
=
logging
.
CRITICAL
,
message
=
'3'
))
handler
.
close
()
# Now test with respect_handler_level set
handler
=
support
.
TestHandler
(
support
.
Matcher
())
handler
.
setLevel
(
logging
.
CRITICAL
)
listener
=
logging
.
handlers
.
QueueListener
(
self
.
queue
,
handler
,
respect_handler_level
=
True
)
listener
.
start
()
try
:
self
.
que_logger
.
warning
(
self
.
next_message
())
self
.
que_logger
.
error
(
self
.
next_message
())
self
.
que_logger
.
critical
(
self
.
next_message
())
finally
:
listener
.
stop
()
self
.
assertFalse
(
handler
.
matches
(
levelno
=
logging
.
WARNING
,
message
=
'4'
))
self
.
assertFalse
(
handler
.
matches
(
levelno
=
logging
.
ERROR
,
message
=
'5'
))
self
.
assertTrue
(
handler
.
matches
(
levelno
=
logging
.
CRITICAL
,
message
=
'6'
))
ZERO
=
datetime
.
timedelta
(
0
)
...
...
Misc/NEWS
Dosyayı görüntüle @
365701ad
...
...
@@ -13,6 +13,9 @@ Core and Builtins
Library
-------
- logging.handlers.QueueListener now takes a respect_handler_level keyword
argument which, if set to True, will pass messages to handlers taking handler
levels into account.
What'
s
New
in
Python
3.5
alpha
1
?
=================================
...
...
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