Message90328
> 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. |
|
Date |
User |
Action |
Args |
2009-07-09 13:48:28 | vinay.sajip | set | recipients:
+ vinay.sajip, srid, hpk |
2009-07-09 13:48:28 | vinay.sajip | set | messageid: <1247147308.48.0.357012194202.issue6333@psf.upfronthosting.co.za> |
2009-07-09 13:48:27 | vinay.sajip | link | issue6333 messages |
2009-07-09 13:48:26 | vinay.sajip | create | |
|