Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: redirect stderr to syslog? Date: Mon, 18 Aug 2014 13:52:37 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 21 Message-ID: References: NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1408369957 15256 64.122.56.22 (18 Aug 2014 13:52:37 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 18 Aug 2014 13:52:37 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) X-Received-Bytes: 1905 X-Received-Body-CRC: 805017177 Xref: csiph.com comp.lang.python:76478 On 2014-08-16, Terry Reedy wrote: > On 8/15/2014 11:04 PM, Russell E. Owen wrote: >> We are using the syslog module for logging, and would like to redirect >> stderr to our log. Is there a practical way to do it? > > You can replace sys.stderr with any object with a .write(s) method. Just a remender: that that will only affect Python code running in the current VM. It doesn't actually change the Unix "stderr" file descriptor (file number 2) that _might_ still be used by some external libraries to print error messages, and it won't affect any child processes (even Python apps). You can deal with those cases by replacing the standard error file descriptor with a log handler, but it's a bit fiddly -- so I won't bother you with the details unless it turns out you really need to do that. -- Grant Edwards grant.b.edwards Yow! I can't decide which at WRONG TURN to make first!! gmail.com I wonder if BOB GUCCIONE has these problems!