Is it possible to print different levels to different streams using the logging module?

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun Jan 17 04:26:26 EST 2010


On Jan 16, 2:32 pm, Dotan Barak <dota... at gmail.com> wrote:
> Hi.
>
> I would like to use theloggingmodule and print the following levels to
> the mentioned streams:
>
> CRITICAL    -> stderr
> ERROR         -> stderr
> WARNING   -> stderr
> INFO             -> stdout
> DEBUG         -> stdout
>
> I would like that every message will be printed only once, and for the
> stream that i choose.
> (I failed to find a "maximum level" for the handlers in theloggingmodule).
>
> Thanks in advanced
> Dotan Barak

Peter's answer is good, and you can also look at a slightly different
take on it (for a slightly different requirement - printing INFO only
to stdout, and everything else to stderr).

http://stackoverflow.com/questions/1383254/logging-streamhandler-and-standard-streams/1383365#1383365

Regards,

Vinay Sajip



More information about the Python-list mailing list