[Python-Dev] Re: PEP 282 comments

Trent Mick trentm@ActiveState.com
Thu, 21 Mar 2002 02:35:58 -0800


[Vinay Sajip wrote]
> [Trent]
> > Here is why I really like this idea now. As per usual, any log message
> > call has the 'msg, *args' arguments. But, in addition, arbitrary objects
> > can be passed in as keyword arguments. These objects get slapped into the
> > LogRecord's __dict__ and any subsequent Handler and/or Formatter can work
> > with those objects. For example, if I want to log some arbitrarily
> > complex object I can just add it to the log record. On the handling end,
> > I could have a Formatter that knows how to deal with that object. For
> > formatters that *don't* recognize certain objects, a reasonable default
> > like using the pprint module could be used.
> 
> I like this. I prefer the name "exc_info" (rather than "exc") for the key,
> as it is clearer that the result of  sys.exc_info(), or equivalent, is being
> passed. 

Agreed. I prefer 'exc_info' too.


> How about the following? The kwargs is searched for "exc_info", and
> if found it is copied to the LogRecord [and removed from kwargs]. The kwargs
> dict is then bound to a "user_info" attribute of the LogRecord.


> There is a potential minefield here - if we are allowing any logging record
> to be sent by wire to a remote logger, then the "user_info" needs to go
> too - and what if something in it can't be pickled? Given that it is really
> important that the logging system is silent except when explicitly asked to
> do something by a logging call, exceptions caught in the logging system are
> generally ignored by design. This means that pickling exceptions would not
> be raised, and I foresee difficulties for developers... The idea of allowing
> arbitrary objects into the LogRecord is very powerful and has much to
> commend it, but I think the pickling problem may need to be solved first.
> 
> What do you think?

How about pulling out exc_info above, as you described, and then just dumping
the rest of the keyword args. No user_info, no mine field. If we come up with
a "mine sweeper" later then we can decide to pass on other keywords if it
looks reasonable and useful. So effectivly we are just trying to express: 

    def log(self, level, msg, *args, exc_info=None): ...

but have to use:

    def log(self, level, msg, *args, **kwargs): ...
        # dump anything but kwargs["exc_info"]

because the former is a syntax problem.

Thoughts?

Trent

p.s. Vinaj, when do you sleep? :)

-- 
Trent Mick
TrentM@ActiveState.com