[Tutor] logging stderr

Joseph J. Strout joe@strout.net
Mon, 19 Apr 1999 12:35:39 -0700


At 12:24 PM -0700 04/19/99, Arne Mueller wrote:

>is there a way to write messages normally going to 'sys.stderr' (e.g.
>pythons error messages) to a file AND to 'sys.stderr' (on unix) without
>changing all my 'sys.stderr.write('...')' statements of the source
>files?

Sure!  (It's Python -- there's always a way!)  Just create an object that
has a write() method.  The code of this method will log to a file, and to
whatever the previous sys.stderr went to (you'll need to save that,
probably in a member variable).  Then assign sys.stderr to this method.
Presto!

Cheers,
-- Joe
,------------------------------------------------------------------.
|    Joseph J. Strout           Biocomputing -- The Salk Institute |
|    joe@strout.net             http://www.strout.net              |
`------------------------------------------------------------------'