[Python-Dev] PEP282 and the warnings framework
Wed, 22 May 2002 09:03:07 +0100
> > It might appear that allowing subclasses of LogRecord is the more
> > thing to do. But this has the potential to stop me from extending
> > LogRecord's functionality in the future, as some new attribute I
> > might conflict with the same-named attribute in some user's
> > LogRecord-derived class. Since I want to preserve this freedom for
> > and other maintainers of logging,
> But you have the same problem with Logger, which is made to be
> subclassed. And Logger probably changes more often than LogRecord.
Not necessarily. LogRecord is a grab-bag for attributes, I expect more
volatility in LogRecord attributes (in the sense that even if I only make a
similar number of attribute changes to LogRecord and to Logger, I would
expect may more changes by users to LogRecord than to Logger - or at least,
I wouldn't be surprised if that were the case).
> > 1. Use a keyword argument, extra_info=None. You can use this on any call
> > such as warn(), debug() etc. just as exc_info is currently used. A
> > value would become the extra_info attribute of the LogRecord.
> This smells to much like extensibility to per-OO way, i.e. simple add a
> void *user_data to every struct you have and you're done.
It's not necessarily a bad smell. It's analogous to the "inheritance or
composition?" question. There are many cases where designers wrongly use
inheritance where composition will suffice.
> > 2. Use the "msg" parameter, which all logging calls already have, to
> > the semantics such that it is either a format string, or an instance
> > that str(msg) returns the desired format string. For the simple case,
> > pass in a string. For the more complex case, pass an instance - the
> > can put any state in there that they want. It will not be used by the
> > logging module, except to call __str__() on it for the format string.
> > can be used by user-derived classes, which will find it in the msg
> > of the LogRecord. This might seem "hackish" to some, but it's not
> > it's just a question of packaging.
> This is more or less the same as 1.: use an (additional) argument, that
> will become an attribute of the LogRecord.
Yes - a minor variation.
> > Slightly OT: There's a lot of people who think that the logging system
> > should be a completely generalized system for event generation and
> > processing. I've shied away from using a word like "Event", preferring
> > "LogRecord" which tries to indicate that this is a focused class for a
> > specific job.
> Even if LogRecord was renamed Event, it would be a "focused class for a
> specific job", because it would be logging.Event. But the name is not so
> important as the functionality.
Yes, but focused for what job? Names *can* be important. I've committed my
share of naming boo-boos in the past, and no doubt will in the future. But
Event, even when qualified with "logging.", signifies to me a more general
construct (e.g. used for more general messaging applications) than a
"LogRecord" (used for holding information about a specific error/diagnostic
logging event). I suppose LogEvent would be OK, too - I think I just picked
LogRecord to echo the PEP.
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com