brubeck
brubeck copied to clipboard
add pub sub logging
within the app I would pass the logger object, which is simply a zeromq PUB socket.
ctx = zmq.Context()
logging_sock = ctx.socket(zmq.PUB)
logging_sock.bind("tcp://127.0.0.1:9955")
config = {
'msg_conn': Mongrel2Connection('tcp://127.0.0.1:9999', 'tcp://127.0.0.1:9998', logger=logging_sock),
'handler_tuples': [(r'^/chatsocket', WebsocketHandler),
(r'^/', DisplayChatPage)],
}
app = Brubeck(**config)
app.run()
m2reader.py looks like this:
import zmq
ctx = zmq.Context()
s = ctx.socket(zmq.SUB)
s.connect("tcp://127.0.0.1:9955")
s.setsockopt(zmq.SUBSCRIBE, "")
while True:
msg = s.recv()
print msg
Considering that a WSGI server wouldn't normally have a need to run zeromq, I don't know how you would want to handle logging with WSGIConnection.
I agree with what you've said, except for the wsgi logging piece. WSGI also receives messages that need to be parsed and it could be neat to provide a flag for printing those values out too.
Specifically, that extra logging could be put somewhere near here: https://github.com/j2labs/brubeck/blob/master/brubeck/connections.py#L238 - rather than use ZMQ, which makes no sense, as you've described, I like the idea of perhaps just writing to whatever the logging mechanism in the system is. If there's a ZMQ logger, that could be used. If it's python's built in logger, that could be used. If it's an external service of some sort, that could be used.
Do you have thoughts, concerns on this idea? I'm thinking out loud on this one.
Would it be advisable to simply add 2 keyword arguments to Connection objects with default values of None:
# uses the Python logging module
logging_logger=None
wherein self.recv inside either WSGIConnection or Mongrel2Connection can call Python's logging.getLogger([name]) using name as the value passed to logging_logger?
The other logger would be:
# would be a zeromq PUB socket, used as described in this initial pull request
zmq_logger=None
This way you could use either or both in either Classes.
Hmm... Let me think on this one a little longer.