Using %(here)s in logging config

1,275 views
Skip to first unread message

kochhar

unread,
Jul 31, 2009, 3:05:32 PM7/31/09
to pylons-...@googlegroups.com
Hi all,

I'm trying to use the %(here)s variable in my logging config but I get the
following error:

ConfigParser.InterpolationMissingOptionError: Bad value substitution:
section: [handler_file]
option : args
key : here
rawval : ('%(here)s/var/log/krumplez.local.log', 'midnight', 1, 3)

The corresponding section of my ini file is:

[handler_file]
class = handlers.TimedRotatingFileHandler
args = ('%(here)s/var/log/kurmplez.local.log', 'midnight', 1, 3)
level = NOTSET
formatter = generic

Google wasn't very helpful in figuring out how to configure logging output to a
directory relative to the config file. Is there some trick to getting the
interpolation to work? The comment at the top of the file says:
# The %(here)s variable will be replaced with the parent directory of this file
#


Thanks,
- kochhar

Mike Orr

unread,
Aug 2, 2009, 2:37:03 AM8/2/09
to pylons-...@googlegroups.com

The file is used in two different ways. Variables are extracted using
paste.deploy.loadwsgi.NicerConfigParser, which interpolates %(here)s.
Logging configuration is done by logging.config.fileConfig, which
doesn't know about interpolation. You'll probably have to use
absolute paths. Or if you're running the application under
Supervisor, you can let it default to stdout and then redirect it to a
file in the Supervisor config.

--
Mike Orr <slugg...@gmail.com>

kochhar

unread,
Aug 3, 2009, 5:41:57 AM8/3/09
to pylons-...@googlegroups.com

That's quite non-intuitive. What's the benefit of lumping the configs together
if they behave differently? Could NicerConfigParser be used to generate an
temporary interpolated version of the config file to give to logging's
fileConfig? I'd be happy to write a patch if that's a reasonable fix.

> You'll probably have to use
> absolute paths. Or if you're running the application under
> Supervisor, you can let it default to stdout and then redirect it to a
> file in the Supervisor config.

I'm using absolute paths now, it makes running the app from multiple locations
painful.

Mike Orr

unread,
Aug 3, 2009, 11:46:36 AM8/3/09
to pylons-...@googlegroups.com

The 'benefit' is using Python's standard configuration mechanism. The
code is all in paste.deploy.loadwsgi or thereabouts, so you'd have to
file a bug there and convince Ian to include it.

One thing I wish it would do is to configure the logging when loading
the file standalone; e.g., in model tests. Currently it configures
logging only when you go through 'paster serve'.

--
Mike Orr <slugg...@gmail.com>

Philip Jenvey

unread,
Aug 3, 2009, 10:30:46 PM8/3/09
to pylons-...@googlegroups.com

On Aug 3, 2009, at 2:41 AM, kochhar wrote:

>
> Mike Orr wrote:
>> On Fri, Jul 31, 2009 at 12:05 PM, kochhar<kochh...@gmail.com>
>> wrote:
>>
>> The file is used in two different ways. Variables are extracted
>> using
>> paste.deploy.loadwsgi.NicerConfigParser, which interpolates %(here)s.
>> Logging configuration is done by logging.config.fileConfig, which
>> doesn't know about interpolation.
>
> That's quite non-intuitive. What's the benefit of lumping the
> configs together
> if they behave differently? Could NicerConfigParser be used to
> generate an
> temporary interpolated version of the config file to give to logging's
> fileConfig? I'd be happy to write a patch if that's a reasonable fix.


fileConfig accepts a set of defaults to pass to ConfigParser, so I've
made PasteScript's logging config loader pass 'here' (and also
'__file__' which PasteDeploy apparently sets up):

http://trac.pythonpaste.org/pythonpaste/changeset/8052

--
Philip Jenvey

Mike Orr

unread,
Aug 4, 2009, 2:28:15 PM8/4/09
to pylons-...@googlegroups.com

How does that work? The defaults are supposed to be
logging.basicConfig arguments, not 'here' and '__file__', which
basicConfig doesn't know what to do with.

--
Mike Orr <slugg...@gmail.com>

Philip Jenvey

unread,
Aug 4, 2009, 3:07:19 PM8/4/09
to pylons-...@googlegroups.com


No, they're just defaults for ConfigParser. basicConfig isn't involved
at all with fileConfig

--
Philip Jenvey

kochhar

unread,
Aug 4, 2009, 7:15:28 PM8/4/09
to pylons-...@googlegroups.com

Thanks! Is a new release planned anytime soon? I could track trunk if it's going
to be a while.

- kochhar

Reply all
Reply to author
Forward
0 new messages