[Python-Dev] PEP282 and the warnings framework

Steven Lott s_lott@yahoo.com
Fri, 17 May 2002 08:27:34 -0700 (PDT)


> [Steve]
> > I think your previous example showed that subject-level
> > filtering required a separate logger/channel per subject.
[snip]
> 
> > The point here is that subjects can (and often are) as
> > fine-grained as individual methods of a class.  Sometimes
> > they are even more fine-grained when dealing with fairly
> > complex algorithms, although this is rare.
> >
> > When I need fine-grained subjects management, I don't want
> > to have many logger/channel instances.  I want to have one
> > channel with a subject attached to each loggable Event.
> 
> Then you can do...
> 
> logger = logging.getLogger("")    #root logger
> 
> logger.log(logging.INFO, "subject 1", ...)
> logger.log(logging.WARN, "subject 2", ...)
> 
> etc.
> 
> A filter can process these events:
> 
> class SubjectFilter(Filter):
>     def filter(self, record):
>         if record.msg == "subject 1":
>             ...
>         elif record.msg == "subject 2":
>             ...
> 
> My example's a bit crude, but you get the picture.

Yes, very clearly.  This is far too cumbersome for fine-grained
control of subjects.  

An individual logger/channel per subject is too difficult
to use for large or complex applications.

[snip]

> > The constructor for a loggable Event would accept an
> > Exception as an argument and create a new loggable Event
> > from the Exception's attributes.
> 
> This is not exactly how it happens, but the effect is
> analogous. Currently,
> the LogRecord constructor is not exposed to users (since it
> was meant as an
> internal class); this may change in the future.

Excellent.  Exposing the LogRecord (maybe renamed to a 
LogEvent in v2.x) is a very nice solution, permitting flexible
creation of LogEvent instances from Exceptions.

This also allows adding Subject information to the LogEvent,
and doing proper fine-grained subject filtering without
creating innumerable channels.

[snip]

=====
--
S. Lott, CCP :-{)
S_LOTT@YAHOO.COM
http://www.mindspring.com/~slott1
Buccaneer #468: KaDiMa

Macintosh user: drinking upstream from the herd.

__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com