[Python-ideas] logging.config.defaultConfig()

Thomas Güttler guettli at thomas-guettler.de
Sat May 17 14:04:12 CEST 2014


Am 17.05.2014 10:56, schrieb Nick Coghlan:
> On 16 May 2014 21:34, M.-A. Lemburg <mal at egenix.com> wrote:
>> On 16.05.2014 11:54, Antoine Pitrou wrote:
>>>> While I agree that importing a module might not be the right way, having
>>>> a standard way to configure logging via environment variables might be
>>>> helpful.
>>>
>>> I entirely disagree. An environment variable is a very lousy way to
>>> specify a configuration file's location; and there is no reason to have
>>> a common logging configuration for all Python applications.
>>
>> Hmm, it's a fairly standard way to define config file locations esp.
>> on Unix platforms, so I don't follow you here. Perhaps I'm just
>> missing some context.
>>
>> Such env vars are often used in application environments to override
>> system defaults, e.g. for finding OpenSSL or ODBC config files.
> 
> Python is a language runtime, not an application. Having globally
> configurable behaviours for a runtime is, in general, questionable,
> which is why we have the options to ignore the environment variables,
> site-packages, user site-packages and now the "isolated mode" flag
> that basically says "ignore *every* explicitly configurable Python
> setting in the environment".

Using logging as library works well in Python. But writing console
scripts which use logging force the developer to solve the same
problems again and again: How to set up the logging?

And the developer of the console script does
not know how the user of the console script wants to handle logging.

That's why all Python application have a different way to set up the logging.

> For 3.2+, we defined a sensible default logging configuration (warning
> and above written to stderr, everything else ignored), so users should
> be free to just use the logging module when writing libraries without
> worrying about whether or not it has been configured for reporting
> properly. That doesn't help Python 2 users, but that's the case for a
> lot of things.

 
> Trying to provide a way to actually *configure* logging in a general
> way would be fraught with backwards compatibility issues when it came
> to interfering with frameworks (whether for writing CLI applications,
> web applications, or GUI applications) that already providing their
> own way of handling logging configuration.

Of course a standard way to get the logging configuration defined by the end user
should be optional. I don't see any backwards compatibility issues.

The author of the console script should just need one line, to
get the defaults which the console script user wants.

{{{
import argparse

def main()
    logging.config.defaultConfig()
    argparse...

}}}

The end user can set up the logging in the way he wants:

 - Log to a file
 - Log to a daemon
 - Format the messages the way he likes it
 - ...

Since I know that some logging environments are complicated, I think
it is best to hook into a method call. There are environments
where fileConfig() does not solve all needs.

Please ask if, you don't understand what I want.


 Thomas Güttler

-- 
Thomas Güttler
http://thomas-guettler.de/


More information about the Python-ideas mailing list