开发者

CherryPy: Log access and error events to syslog

I have created a REST interface using CherryPy. I prefer using syslog, instead of individual files to log messages for each of my applications. So, currently, the application uses the Python logging facility, logging to syslog via a /dev/log handler.

I would like to be able to log all of the access attempts at the debug level, and all of the errors at the error level, which you can do by specifying the cherrypy.log.access_file and cherrypy.lo开发者_如何学Cg.error_file file-paths.

Is there a way to direct the cherrypy.log.error_file to syslog? I would like to avoid logging directly to /var/log/syslog and changing the permissions on that file, if possible.

Thanks,

Zach


I see how to do this:

I have my logging defined in my configuration file using Python's logging facility. I have initialized a logger for general purposes based on that.

Using the documentation here: http://docs.cherrypy.org/stable/refman/_cplogging.html, I added my syslog handler to the cherrypy.log handlers.

Here is my code:

from cherrypy import log

h = logger.handlers[0]
h.setLevel(logging.DEBUG)
log.access_log.addHandler(h)
log.error_log.addHandler(h)

It's super simple.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜