[zeromq-dev] Python logging via zeromq

andrea crotti andrea.crotti.0 at gmail.com
Mon Aug 13 16:39:37 CEST 2012

2012/8/13 andrea crotti <andrea.crotti.0 at gmail.com>:
> 2012/8/13 Brian Knox <briank at talksum.com>:
>> This might interest you:
>> http://zeromq.github.com/pyzmq/logging.html
> Great, exactly what I wanted to implement, thanks!

I can't understand how to actually subscribe to the logger though,
this example doesn't quite work..
If I subscribe to '' it should get all the possible messages right?

import sys
import zmq
import logging

from zmq.log.handlers import PUBHandler
PORT = 'tcp://*:6666'

if __name__ == '__main__':
    if len(sys.argv) > 1:
        context = zmq.Context()
        sock = context.socket(zmq.PUB)

        handler = PUBHandler(sock)

        root = logging.getLogger()

        root.debug("topic.subtopic::debug message")
        root.info("Info message")
        while True:
            root.info(raw_input("What do you want to say?"))

        context = zmq.Context()
        sock = context.socket(zmq.SUB)
        sock.setsockopt(zmq.SUBSCRIBE, '')
        while True:
            msg = sock.recv()
            print("got message %s" % msg)

More information about the zeromq-dev mailing list