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.

classification
Title: logging.StreamHandler ignores argument if it compares False
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: nnorwitz, slinkp, vinay.sajip
Priority: normal Keywords:

Created on 2006-04-03 21:37 by slinkp, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
__init__.py.patch slinkp, 2006-04-03 21:37
Messages (3)
msg28033 - (view) Author: Paul Winkler (slinkp) * Date: 2006-04-03 21:37
The docs at http://docs.python.org/lib/node346.html say
this:
"""
class StreamHandler(  	[strm])
    Returns a new instance of the StreamHandler class.
If strm is specified, the instance will use it for
logging output; otherwise, sys.stderr will be used.
"""

However, that's not quite true.
StreamHandler.__init__() actually tests for truth of
strm, which means you have to be careful that strm does
not happen to evaluate to boolean false.

My use case: I'm writing some tests that verify that
certain methods put certain strings into the logs. So
my setUp() adds a StreamHandler with its stream set to
an instance of this trivial class:

class FakeLog(list):
    def write(self, msg):
        self.append(msg)
    def flush(self):
        pass

... which does not work, because an empty list
evaluates to false, so my handler writes to stderr even
though i told it not to.  It's trivial to work around
this by adding a __nonzero__ method, but the need to do
so is certainly not clear from the docs. Therefore imho
this is a bug. The patch is trivial, and is attached.
msg28034 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-04-04 06:20
Logged In: YES 
user_id=33168

Vinay, any comments?  We are preparing for 2.5 alpha1 within
a day.  There will be freeze real soon now.
msg28035 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2006-04-11 21:45
Logged In: YES 
user_id=308438

Fix checked into Subversion.
History
Date User Action Args
2022-04-11 14:56:16adminsetgithub: 43152
2006-04-03 21:37:50slinkpcreate