[issue16110] Provide logging.config.configParserConfig

thbach report at bugs.python.org
Thu Oct 4 23:11:12 CEST 2012


thbach added the comment:

vinay: I understand your preference of dictConfig over fileConfig as maintainer. But as an application developer I want to provide my user an easy way to adjust logging herself. In the end of the day she is the one knowing what has to be logged in which place. Therefor, having something like fileConfig is essential.

david: The modified configuration can be passed to fileConfig via a StringIO instance. 

The downside is that ConfigParser instances with e.g. 'allow_no_value' set to True are currently difficult to handle – e.g.:

>>> sys.version
'3.2.3 (default, Jun 25 2012, 23:10:56) \n[GCC 4.7.1]'
>>> cp = configparser.ConfigParser(allow_no_value=True)
>>> cp.read_string('[foo]\nbar')
>>> buf = io.StringIO()
>>> cp.write(buf)
>>> buf.seek(0)
0
>>> logging.config.fileConfig(buf)
---------------------------------------------------------------------------
ParsingError                              Traceback (most recent call last)
<ipython-input-67-0717fe665796> in <module>()
----> 1 logging.config.fileConfig(buf)

/usr/lib/python3.2/logging/config.py in fileConfig(fname, defaults, disable_existing_loggers)
     64     cp = configparser.ConfigParser(defaults)
     65     if hasattr(fname, 'readline'):
---> 66         cp.read_file(fname)
     67     else:
     68         cp.read(fname)

/usr/lib/python3.2/configparser.py in read_file(self, f, source)
    706             except AttributeError:
    707                 source = '<???>'
--> 708         self._read(f, source)
    709 
    710     def read_string(self, string, source='<string>'):

/usr/lib/python3.2/configparser.py in _read(self, fp, fpname)
   1079         # if any parsing errors occurred, raise an exception
   1080         if e:
-> 1081             raise e
   1082         self._join_multiline_values()
   1083 

ParsingError: Source contains parsing errors: <???>
	[line  2]: 'bar\n'

Hence, logging.config.fileConfig should at least provide a way to pass in arguments for the ConfigParser initialization. Anyways, I think it is much cleaner to provide a function which gets the configuration directly from the ConfigParser instance.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16110>
_______________________________________


More information about the Python-bugs-list mailing list