25
25
import sys
26
26
import os
27
27
import errno
28
-
28
+ import logging
29
+ from logging import handlers
29
30
from queryHandler .QueryHandler import PerfmonConnError
30
31
from queryHandler import SensorConfig
31
32
from __version__ import __version__
@@ -49,17 +50,36 @@ def processFormJSON(entity):
49
50
cherrypy .serving .request .json = json .loads ('{}' )
50
51
51
52
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 = ""
53
60
54
61
path = args .get ('logPath' )
55
62
if not os .path .exists (path ):
56
63
os .makedirs (path )
57
64
accesslog = os .path .join (path , 'cherrypy_access.log' )
58
65
errorlog = os .path .join (path , 'cherrypy_error.log' )
59
66
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
+
60
82
globalConfig = {'global' : {'server.socket_port' : args .get ('port' ),
61
- 'log.access_file' : accesslog ,
62
- 'log.error_file' : errorlog ,
63
83
# default error response
64
84
'error_page.default' : format_default_error_page ,
65
85
# unexpected errors
@@ -139,6 +159,9 @@ def main(argv):
139
159
logger = configureLogging (args .get ('logPath' ), args .get ('logFile' , None ),
140
160
args .get ('logLevel' ))
141
161
162
+ # prepare cherrypy logging configuration
163
+ setup_cherrypy_logging (args )
164
+
142
165
# prepare cherrypy server configuration
143
166
updateCherrypyConf (args )
144
167
if args .get ('protocol' ) == "https" :
0 commit comments