Author vinay.sajip
Recipients hpk, srid, vinay.sajip
Date 2009-07-09.13:48:26
SpamBayes Score 8.15834e-05
Marked as misclassified No
Message-id <1247147308.48.0.357012194202.issue6333@psf.upfronthosting.co.za>
In-reply-to
Content
> Is it a problem to have the logging module be a bit more defensive and
> only try a flush/close if the stream isn't already closed?

Not particularly, but it would be better if the following approach were
taken:

import logging
import StringIO
stream = StringIO.StringIO()
h = logging.StreamHandler(stream)
r = logging.getLogger()
r.addHandler(h)
#Do your testing work
r.removeHandler(h)
h.close() # closes underlying stream, also removes logging refs to h

It should be understood that if a stream is passed to a StreamHandler,
the ownership of that stream is passed as well, so closing the handler
rather than the underlying stream is the right thing to do. ISTM this is
good practice in general and not exclusive to logging.
History
Date User Action Args
2009-07-09 13:48:28vinay.sajipsetrecipients: + vinay.sajip, srid, hpk
2009-07-09 13:48:28vinay.sajipsetmessageid: <1247147308.48.0.357012194202.issue6333@psf.upfronthosting.co.za>
2009-07-09 13:48:27vinay.sajiplinkissue6333 messages
2009-07-09 13:48:26vinay.sajipcreate