Can log and CherryPy use the same configuration file?

Both Python logging module and CherryPy Config API use ConfigParser files. Therefore, I suggested that I could use one single configuration file for my own application configuration, registration configuration, and CherryPy configuration.

When my records and CherryPy were separate, they worked perfectly, and my configuration file processed without errors using the ConfigParser api. However, CherryPy seems to be barf in this section:

[loggers] keys=root,myapp,cherrypy,cperror,cpaccess 

giving the following exception:

 Traceback (most recent call last): File "/usr/lib/python2.6/multiprocessing/process.py", line 232, in _bootstrap self.run() File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run self._target(*self._args, **self._kwargs) File "unittests.py", line 431, in main cherrypy.config.update(server.CONFIG_FILE) File "/usr/lib/pymodules/python2.6/cherrypy/_cpconfig.py", line 263, in update config = _Parser().dict_from_file(config) File "/usr/lib/pymodules/python2.6/cherrypy/_cpconfig.py", line 383, in dict_from_file return self.as_dict() File "/usr/lib/pymodules/python2.6/cherrypy/_cpconfig.py", line 374, in as_dict raise ValueError(msg, x.__class__.__name__, x.args) ValueError: ("Config error in section: 'loggers', option: 'keys', value: 'root,myapp,cherrypy,cperror,cpaccess'. Config values must be valid Python.", 'TypeError', ("unrepr could not resolve the name 'root'",)) 

CherryPy docs never say that CherryPy requires its configuration file to be separate from your other configuration, but I'm starting to think it might be necessary. The docs indicate that the site and application configuration can be separate if there are several applications on the same site, but this seems like a different problem ... is my registration configuration incorrect for the CherryPy application configuration?

Is it possible? If not, I'm not sure why CherryPy even bothers using the ConfigParser library in the first place.

+4
source share
1 answer

Short answer: no, you probably can't mix them. As described in docs : "Configuration entries are always a key / value pair, for example server.socket_port = 8080. The key is always a name, and the value is always a Python object. That is, if the value you set is int (or another number) , it should look like a Python int, for example 8080. If this value is a string, it should be quoted in the same way as a Python string. "

Although we want to use arbitrary Python types in our CherryPy configuration values, CherryPy uses ConfigParser simply because we did not want to write our own parser for section and write syntax.

+4
source

All Articles