Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add pub sub logging #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

add pub sub logging #70

wants to merge 1 commit into from

Conversation

stuntgoat
Copy link
Contributor

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.

@j2labs
Copy link
Owner

j2labs commented May 17, 2012

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.

@stuntgoat
Copy link
Contributor Author

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.

@j2labs
Copy link
Owner

j2labs commented May 17, 2012

Hmm... Let me think on this one a little longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants