2024-05-21 13:59:20 发布
网友
如果我希望Cherrypy的访问日志只有一个固定的大小,那么如何使用循环日志文件呢?在
我已经尝试过http://www.cherrypy.org/wiki/Logging,它似乎过时了,或者缺少信息。在
看http://docs.python.org/library/logging.html。在
您可能需要配置RotatingFileHandler
http://docs.python.org/library/logging.html#rotatingfilehandler
custom log handlers的CherryPy文档展示了这个例子。在
以下是我在我的应用程序中使用的稍作修改的版本:
import logging from logging import handlers def setup_logging(): log = cherrypy.log # Remove the default FileHandlers if present. log.error_file = "" log.access_file = "" maxBytes = getattr(log, "rot_maxBytes", 10000000) backupCount = getattr(log, "rot_backupCount", 1000) # Make a new RotatingFileHandler for the error log. fname = getattr(log, "rot_error_file", "log\\error.log") h = handlers.RotatingFileHandler(fname, 'a', maxBytes, backupCount) h.setLevel(logging.DEBUG) h.setFormatter(cherrypy._cplogging.logfmt) log.error_log.addHandler(h) # Make a new RotatingFileHandler for the access log. fname = getattr(log, "rot_access_file", "log\\access.log") h = handlers.RotatingFileHandler(fname, 'a', maxBytes, backupCount) h.setLevel(logging.DEBUG) h.setFormatter(cherrypy._cplogging.logfmt) log.access_log.addHandler(h) setup_logging()
I've already tried http://www.cherrypy.org/wiki/Logging, which seems out of date, or has information missing.
尝试添加:
import logging import logging.handlers import cherrypy # you might have imported this already
而不是
也许可以试试
log = cherrypy.log
看http://docs.python.org/library/logging.html。在
您可能需要配置RotatingFileHandler
http://docs.python.org/library/logging.html#rotatingfilehandler
custom log handlers的CherryPy文档展示了这个例子。在
以下是我在我的应用程序中使用的稍作修改的版本:
尝试添加:
而不是
^{pr2}$也许可以试试
相关问题 更多 >
编程相关推荐