This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <>
> 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

import logging
import StringIO
stream = StringIO.StringIO()
h = logging.StreamHandler(stream)
r = logging.getLogger()
#Do your testing work
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:28vinay.sajipsetrecipients: + vinay.sajip, srid, hpk
2009-07-09 13:48:28vinay.sajipsetmessageid: <>
2009-07-09 13:48:27vinay.sajiplinkissue6333 messages
2009-07-09 13:48:26vinay.sajipcreate