Bugs item #1164953, was opened at 2005-03-16 20:38
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1164953&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: logistix (logistix)
Assigned to: Nobody/Anonymous (nobody)
Summary: logging.basicConfig creates phantom handler

Initial Comment:
calling logging.basicConfig() creates a phantom handler 
that doesn't operate in an intuitive way.  A reproducable 
follows.

My actual use case:  I started off using the logging 
module on a project with the builting logging.info(), 
logging.debug(), logging.error() functions.  As my needs 
got more sophisticated, I started creating some loggers 
via logging.getLogger('a.b.c')  I setup a custom handler 
to do formatting without printing "INFO:a.b.c" headers.  
One of my import statements triggered a call to 
logging.basicConfig.  Halfway through the running 
program, my logging messages started showing up 
twice.  Once without the header and once with.  I 
eventually tracked this down to usage of a logging.info() 
statement.  I tried explicitly calling logging.basicConfig
(level=logging.ERROR) to disable the duplicate errors, 
but that didn't work.

A trivial patch is attached.  It fixes the problem if you 
explicitly call logging.basicConfig.  I don't know if it will 
fix the implicit calls by logging.info(), etc.

C:\Python24>python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import logging
>>>
>>> logger = logging.getLogger('foo')
>>> logger.setLevel(logging.INFO)
>>> logger.info('bar') # no output yet
No handlers could be found for logger "foo"
>>>
>>> console = logging.StreamHandler()
>>> console.setLevel(logging.INFO)
>>> console.setFormatter(logging.Formatter("%
(message)s")
... )
>>> logger.addHandler(console)
>>>
>>> logger.info('foo')
foo
>>>
>>> logger.warning('foo')
foo
>>>
>>> logger.debug('foo')
>>>
>>> logger.info('foo')
foo
>>>
>>> logging.basicConfig(level=logging.ERROR)
>>>
>>> logger.info('foo')
foo
INFO:foo:foo
>>> ^Z


C:\Python24>

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1164953&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to