classification
Title: logging: callHandlers tests handler levels instead of logger levels?
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: artur.ambroziak, gidi_avrahami, vinay.sajip
Priority: normal Keywords:

Created on 2007-11-21 22:41 by gidi_avrahami, last changed 2014-04-14 10:37 by artur.ambroziak. This issue is now closed.

Messages (3)
msg57741 - (view) Author: Gidi Avrahami (gidi_avrahami) Date: 2007-11-21 22:41
I am using the logging module with multiple loggers and the following
behavior seems incorrect to me:

I set the root logger's level to WARN and the foo.bar module's logger's
level to DEBUG, and the foo.bar logger should is writing to a file.  So
basically, I want foo.bar to log itself in details behind the scenes
while the main console is quiet.

However, I still get all the sebug info printed to the console.  When I
trace down the code, I see that callHandlers() is climbing up the logger
hierarchy, but it's comparing record.level to hdlr.level, not to
c.level.  The handler levels, however, don't appear to be set normally
(i.e., after I do getLogger("foo.bar").setLevel, its handlers stay at
level NOTSET).  As a result, callHandlers will call all the handlers
above the first one, no matter what the loggers level.

Is this intentional?  If it is, how should I get the behavior that I
described above?  (I could set propagate=False, but in fact if the rott
logger is DEBUG then I do want it to print the foo.bar messages)
msg57762 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2007-11-22 15:30
The behaviour you describe is intentional. To achieve what you want, you
can either set levels on the handlers or use Filters on loggers and/or
handlers (if level-based filtering is not sufficient for your needs).
msg216070 - (view) Author: Artur (artur.ambroziak) Date: 2014-04-14 10:37
So what is logger level for if it's not used on calling handlers?
History
Date User Action Args
2014-04-14 10:37:32artur.ambroziaksetnosy: + artur.ambroziak

messages: + msg216070
versions: + Python 2.7, - Python 2.5, Python 2.4
2007-11-22 15:30:08vinay.sajipsetstatus: open -> closed
resolution: not a bug
messages: + msg57762
nosy: + vinay.sajip
2007-11-21 22:41:17gidi_avrahamicreate