2009-10-21 63 views

回答

2

的CherryPy不會使用標準Python記錄模塊的日誌記錄。您需要將其更改爲使用RotatingFileHandler。該處理程序將負責處理所有事情,包括在達到設定的最大大小時旋轉日誌。

3

我已經試過http://www.cherrypy.org/wiki/Logging,這似乎是 過時或缺少信息。

嘗試增加:與

import logging 
import logging.handlers 
import cherrypy # you might have imported this already 

代替

log = app.log 

也許嘗試

log = cherrypy.log 
2

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()