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
63891ed0
Kaydet (Commit)
63891ed0
authored
Eyl 13, 2010
tarafından
Vinay Sajip
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Expanded QueueHandler documentation.
üst
ccb706cf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
1 deletion
+34
-1
logging.rst
Doc/library/logging.rst
+34
-1
No files found.
Doc/library/logging.rst
Dosyayı görüntüle @
63891ed0
...
...
@@ -2605,7 +2605,9 @@ supports sending logging messages to a queue, such as those implemented in the
.. class:: QueueHandler(queue)
Returns a new instance of the :class:`QueueHandler` class. The instance is
initialized with the queue to send messages to.
initialized with the queue to send messages to. The queue can be any queue-
like object; it'
s
passed
as
-
is
to
the
:
meth
:`
enqueue
`
method
,
which
needs
to
know
how
to
send
messages
to
it
.
..
method
::
emit
(
record
)
...
...
@@ -2623,6 +2625,37 @@ supports sending logging messages to a queue, such as those implemented in the
The :class:`QueueHandler` class was not present in previous versions.
.. _zeromq-handlers:
You can use a :class:`QueueHandler` subclass to send messages to other kinds
of queues, for example a ZeroMQ "publish" socket. In the example below,the
socket is created separately and passed to the handler (as its '
queue
')::
import zmq # using pyzmq, the Python binding for ZeroMQ
import json # for serializing records portably
ctx = zmq.Context()
sock = zmq.Socket(ctx, zmq.PUB) # or zmq.PUSH, or other suitable value
sock.bind('
tcp
://*:
5556
') # or wherever
class ZeroMQSocketHandler(QueueHandler):
def enqueue(self, record):
data = json.dumps(record.__dict__)
self.queue.send(data)
Of course there are other ways of organizing this, for example passing in the
data needed by the handler to create the socket::
class ZeroMQSocketHandler(QueueHandler):
def __init__(self, uri, socktype=zmq.PUB, ctx=None):
self.ctx = ctx or zmq.Context()
socket = zmq.Socket(self.ctx, socktype)
super(ZeroMQSocketHandler, self).__init__(socket)
def enqueue(self, record):
data = json.dumps(record.__dict__)
self.queue.send(data)
.. _formatter-objects:
...
...
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