2525import sys
2626import os
2727import errno
28-
28+ import logging
29+ from logging import handlers
2930from queryHandler .QueryHandler import PerfmonConnError
3031from queryHandler import SensorConfig
3132from __version__ import __version__
@@ -49,17 +50,36 @@ def processFormJSON(entity):
4950 cherrypy .serving .request .json = json .loads ('{}' )
5051
5152
52- def updateCherrypyConf (args ):
53+ def setup_cherrypy_logging (args ):
54+
55+ log = cherrypy .log
56+
57+ # Remove the default FileHandlers if present.
58+ log .error_file = ""
59+ log .access_file = ""
5360
5461 path = args .get ('logPath' )
5562 if not os .path .exists (path ):
5663 os .makedirs (path )
5764 accesslog = os .path .join (path , 'cherrypy_access.log' )
5865 errorlog = os .path .join (path , 'cherrypy_error.log' )
5966
67+ # Make a new RotatingFileHandler for the error log.
68+ handler = handlers .RotatingFileHandler (errorlog , 'a' , 1000000 , 10 )
69+ handler .setLevel (logging .INFO )
70+ handler .setFormatter (cherrypy ._cplogging .logfmt )
71+ log .error_log .addHandler (handler )
72+
73+ # Make a new RotatingFileHandler for the access log.
74+ handler = handlers .RotatingFileHandler (accesslog , 'a' , 1000000 , 10 )
75+ handler .setLevel (logging .INFO )
76+ handler .setFormatter (cherrypy ._cplogging .logfmt )
77+ log .access_log .addHandler (handler )
78+
79+
80+ def updateCherrypyConf (args ):
81+
6082 globalConfig = {'global' : {'server.socket_port' : args .get ('port' ),
61- 'log.access_file' : accesslog ,
62- 'log.error_file' : errorlog ,
6383 # default error response
6484 'error_page.default' : format_default_error_page ,
6585 # unexpected errors
@@ -139,6 +159,9 @@ def main(argv):
139159 logger = configureLogging (args .get ('logPath' ), args .get ('logFile' , None ),
140160 args .get ('logLevel' ))
141161
162+ # prepare cherrypy logging configuration
163+ setup_cherrypy_logging (args )
164+
142165 # prepare cherrypy server configuration
143166 updateCherrypyConf (args )
144167 if args .get ('protocol' ) == "https" :
0 commit comments