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

Michel Albert exhuma at gmail.com
Tue Aug 30 13:59:32 CEST 2011


On Aug 30, 11:45 am, Peter Otten <__pete... at web.de> wrote:
> Michel Albert wrote:
> > I use python oftentimes to write automation scripts on Linux servers.
> > And there's a big pattern in my scripts:
>
> > - I *always* use `logging` instead of `print` statements.
> > - I *always* create two stream handlers. One for `sys.stdout` with
> > level `INFO` and one for `sys.stderr` with level `WARN`
>
> > Well, the levels may variate occasionally, but that's only the rare
> > exception.
>
> How would a call to basicConfig() look like that produces this setup?

I personally see this happen by default (i.e. no additional
parameters). And in case the `stream` parameter is set, /then/ you
would  send all to that stream only.

In my point of view, the call to `basicConfig` is either something
used in only the most mundane usages of the logging package, or it's
mainly used by people that have not yet grokked the logging package
(correct me if I'm wrong). In both cases, I find it useful to redirect
warnings and errors to `stderr` by default.

However, this would also mean that existing code calling this method
would result in different behavior. But only /slightly/ different.
Meaning, you still see the output on the console as expected. But it
gives you the possibility to use standard shell redirection in a way
that "makes sense".



More information about the Python-list mailing list