On Friday, May 26, 2017 at 8:37:38 AM UTC-4, Tim Williams wrote:
> 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'

Peter,

I'm starting to think that maybe my problem is somewhere with configobj. 
Calling ConfigObj.dict() (really configobj.Section.dict()) tries to interpolate 
the values in the 'format' key, but not when creating the ConfigObj object, but 
it does interpolate the LogFile key value. 

I've spent too much time trying to track this down. I'll just hard-code my 
filename in my INI file. Maybe I'll get back to it, but I need to move on.

Thanks for your help.
Tim
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to