using configobj string interpolation and logging.config.dictConfig

Tim Williams tjandacw at cox.net
Fri May 26 08:37:27 EDT 2017


On Friday, May 26, 2017 at 8:32:19 AM UTC-4, Tim Williams wrote:
> On Thursday, May 25, 2017 at 9:43:40 PM UTC-4, Tim Williams wrote:
> > On Thursday, May 25, 2017 at 5:16:13 PM UTC-4, Peter Otten wrote:
> (snip)
> > > ...
> > > 
> > > How do you get
> > > 
> > > > LogFile = '%(CaptureDrive)s%(RootDir)s/test.log'
> > > 
> > > to be interpolated while leaving
> > > 
> > > > format = '%(asctime)s: (%(levelname)s)  %(message)s'
> > > 
> > > as is?
> > > 
> > > > However, when I try to call logging.config.dictConfig() on it, the stream
> > > > that is opened on creating the logging.FileHandler object is
> > > > "%(LogFile)s", not "C:/TestData/test.log".
> > > 
> > > I don't even get this far:
> > > 
> > > >>> c = configobj.ConfigObj("second.ini", unrepr=True)
> > > >>> c.dict()
> > > Traceback (most recent call last):
> > > ...
> > > configobj.MissingInterpolationOption: missing option "asctime" in 
> > > interpolation.
> > > 
> > > I tried to escape % as %%, but that doesn't seem to work. When I provide 
> > > bogus replacements
> > > 
> > > >>> c = configobj.ConfigObj("third.ini", unrepr=True)
> > > >>> pprint.pprint(c.dict()["loggng"])
> > > {'CaptureDrive': 'C:/',
> > >  'LogFile': 'C:/TestData/test.log',
> > >  'RootDir': 'TestData',
> > >  'asctime': 'ASCTIME',
> > >  'formatters': {'fmt1': {'datefmt': '',
> > >                          'format': 'ASCTIME: (LEVELNAME)  MESSAGE'}},
> > >  'handlers': {'console': {'class': 'logging.StreamHandler',
> > >                           'level': 'INFO',
> > >                           'stream': 'ext://sys.stdout'},
> > >               'file': {'class': 'logging.FileHandler',
> > >                        'filename': 'C:/TestData/test.log',
> > >                        'level': 'WARN'}},
> > >  'level': 'INFO',
> > >  'levelname': 'LEVELNAME',
> > >  'loggers': {'root': {'handlers': ['file', 'console'], 'level': 'INFO'}},
> > >  'message': 'MESSAGE',
> > >  'version': 1}
> > > 
> > > I get the expected output.
> > 
> > I'm at home now, so I don't have my environment, but if I do a c.dict() I get the error about asctime also. If I just pass in the dict object or do a 'dict(config['loggng'])', I don't get that.
> 
> (Back at work.)
> Looking at the non-interpolation of '%(asctime)s', etc again, I'm wondering that myself. Maybe this is a bug in configobj? That doesn't make sense though. I'm wondering if the keyword 'format' has something to do with it.

Changed key 'foramt' to 'formt'. No change on non-interpolation of 
'%(asctime)s'



More information about the Python-list mailing list