[ python-Bugs-876421 ] logging handlers raise exception on level

SourceForge.net noreply at sourceforge.net
Fri Jan 23 17:53:56 EST 2004


Bugs item #876421, was opened at 2004-01-13 22:04
Message generated for change (Comment added) made by vsajip
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=876421&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Jim Jewett (jimjjewett)
Assigned to: Vinay Sajip (vsajip)
Summary: logging handlers raise exception on level

Initial Comment:
logging.__version__ = "0.4.8.1" - matches CVS

Handler() takes a keyword argument of level, for the 
initial level of message it should care about.

StreamHandler inherits from Handler, but does not pass 
the level keyword through when calling Handler__init__.

    #def __init__(self, strm=None):
    def __init__(self, strm=None, **kwargs):

         #Handler.__init__(self)
         # should we delete the key that Stream uses?
         Handler.__init__(self, **kwargs)


I am submitting as a bug rather than a patch because 
several other classes have the same problem, and 
because I am not sure whether arguments used by the 
child initializer (such as strm) should be passed on.




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

>Comment By: Vinay Sajip (vsajip)
Date: 2004-01-23 22:53

Message:
Logged In: YES 
user_id=308438

I'm sorry if you don't find the library very useful. I don't 
regard using setLevel() as a workaround - it was designed 
this way. Not all designers would design things the same way. 
You are the first and only person to raise this issue, after 
many months during which the library has been in use (even 
before Python 2.3 was released). If many people raise this as 
an issue, I will have to rethink this - but right now I don't 
think making a change is justified. I certainly haven't 
regarded the "set up a hander in one line" as a design goal. If 
you use a configuration file, you can set up multiple handlers, 
formatters and loggers in just one or two lines of code. (Not 
that I am recommending using a configuration file - but the 
functionality is there).

Thanks for taking the time to put your point of view, though. 
I genuinely appreciate it.

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

Comment By: Jim Jewett (jimjjewett)
Date: 2004-01-23 22:23

Message:
Logged In: YES 
user_id=764593

One reason to use a standard library is so that my own code 
won't have to worry about any more detail than I want to -- I 
shouldn't even have to read the code within the library for 
implementation details.  

The more study required/glue code needed/state I must keep, 
the less useful the library is.  Keeping a reference and using 
setLevel is a workaround, but it should not be required.  I 
should be able to set up a handler in one line.  For example, to 
log everything and echo important stuff to the user:

logging.addHandler(StreamHandler(level=ERROR))
logging.addHandler(RotatingFileHandler("mylog",level=DEBUG))

(note that the level=DEBUG is only required because the 
default of 0 really turns into WARNING if I don't reset it.)


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

Comment By: Vinay Sajip (vsajip)
Date: 2004-01-22 23:19

Message:
Logged In: YES 
user_id=308438

It's not really odd that Class(arg=val) would work, but 
subClass(arg=val) would fail. This is because there is no 
requirement that base class constructors and derived class 
constructors need to look the same. Of course, the derived 
class needs to understand how to construct the base class.

Please note that the Handler class is a base class, not 
intended to be instantiated - as you know. So your example is 
not really valid.

Please don't submit a patch for this, it's not a bug. I still don't 
understand why you can't use setLevel() to set your level. 
Why does it *have* to be in the constructor?

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

Comment By: Jim Jewett (jimjjewett)
Date: 2004-01-19 17:57

Message:
Logged In: YES 
user_id=764593

In general, it seems odd that Class(arg=val) would work, but 
subClass(arg=val) would fail, unless subclass is designed 
explicitly to restrict capabilities.  

logfile = logging.Handler(level=logging.ERROR) works.[1]  

logfile = logging.StreamHandler(level=logging.ERROR) fails, even 
though the level is still relevant and reasonable.

If I submit a patch for the classes distributed with the library, 
would it be an acceptable change?

[1] Admittedly, this handler might fail later, because Handler.
emit() assumes that Handler is abstract.


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

Comment By: Vinay Sajip (vsajip)
Date: 2004-01-18 19:02

Message:
Logged In: YES 
user_id=308438

I don't think this is a bug. You should consider that 
Handler.__init__() takes a level argument with a default 
value, rather than a keyword argument. This should be 
treated as an internal implementation detail, used only by 
subclasses of Handler. If you are writing a Handler subclass, 
you can pass the level argument via your 
HandlerSubclass.__init__() to Handler.__init__(). Otherwise, 
you can set the level using Handler.setLevel().

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=876421&group_id=5470



More information about the Python-bugs-list mailing list