开发者

How do I do logging in a WSGI application across several processes?

I have a simple webservice written in Python WSGI, it's running in Apache and modwsgi using the WSGIDaemonProcess processes=4 directive.

How开发者_Go百科 do I add logging? Obviously I can't log to the same file without some sort of mutex, but I don't want performance degraded.

The logging can't block. As far as I know the standard logging module blocks on every log call.

I was thinking of doing some sort of socket logging, is this viable? Would it require a "server" process to receive logging? What happens if the server isn't on?


Direct logging output to sys.stderr. Doing that will see anything logged get routed into the internal Apache logging routines and into the Apache error logs. The way Apache does this works when done from multiple process at the same time.


Use SysLogHandler(NTEventLogHandler on Windows) or ConcurrentLogHandler.


Take a look at the logging module in the python docs. They allow for instance logging, so you just spawn a new instance from the log factory and a new file will be written to.

http://docs.python.org/library/logging.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜