Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`?

Vinay Sajip vinay_sajip at yahoo.co.uk
Fri Sep 2 18:59:31 EDT 2011


On Aug 30, 9:53 am, Michel Albert <exh... at gmail.com> wrote:


> Unfortunately this setup makes `logging.basicConfig` pretty useless.
> However, I believe that this is something that more people could
> benefit from. I also believe, that it just "makes sense" to send
> warnings (and above) to `stderr`, the rest to `stdout`.
>
> So I was thinking: "Why does `logging.basicConfig` not behave that
> way".

Because what seems entirely natural and obvious to you might not seem
so for someone else. The API in the stdlib tries to provide baseline
functionality which others can build on. For example, if you always
have a particular pattern which you use, you can always write a
utility function to set things up exactly how you like, and others who
want to set things up differently (for whatever reason) can do the
same thing, without having to come into conflict (if that's not too
strong a word) with views different from their own.

> Naturally, I was thinking of writing a patch against the python
> codebase and submit it as a suggestion. But before doing so, I would
> like to hear your thoughts on this. Does it make sense to you too or
> am I on the wrong track? Are there any downsides I am missing?

Python 2.x is closed to feature changes, and Python 2.7 and Python 3.2
already support flexible configuration using dictConfig() - see

http://docs.python.org/library/logging.config.html#logging.config.dictConfig

Also, Python 3.3 will support passing a list of handlers to
basicConfig(): see

http://plumberjack.blogspot.com/2011/04/added-functionality-for-basicconfig-in.html

which will allow you to do what you want quite easily.

Regards,

Vinay Sajip



More information about the Python-list mailing list