[zeromq-dev] Python logging via zeromq

Michel Pelletier pelletier.michel at gmail.com
Mon Aug 13 18:43:11 CEST 2012


You can't connect() to 'tcp://*:6666', you should be getting an error.
 You need to specify a host or ip.

-Michel

On Mon, Aug 13, 2012 at 7:39 AM, andrea crotti
<andrea.crotti.0 at gmail.com> wrote:
> 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)
>         sock.bind(PORT)
>
>         handler = PUBHandler(sock)
>
>         root = logging.getLogger()
>         root.addHandler(handler)
>
>         root.debug("topic.subtopic::debug message")
>         root.info("Info message")
>         while True:
>             root.info(raw_input("What do you want to say?"))
>
>     else:
>         context = zmq.Context()
>         sock = context.socket(zmq.SUB)
>         sock.connect(PORT)
>         sock.setsockopt(zmq.SUBSCRIBE, '')
>         while True:
>             msg = sock.recv()
>             print("got message %s" % msg)
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev



More information about the zeromq-dev mailing list