[Python-Dev] Re: PEP 282 comments

Vinay Sajip vinay_sajip@red-dove.com
Thu, 21 Mar 2002 01:14:52 -0000


> > def logException(self, level, exc_info, msg, *args)
>
> No need to pass in the exc_info if you are already specifying that an
> exception is being logged via log*Exception*.
Yes, except that you are assuming (I think) that logException would call
sys.exc_info() to get the exception info. This is fine for most cases, but
what about if the exception info needs to come from somewhere else (e.g.
from a pickled message sent over the wire)? I haven't yet thought through
all the issues about passing tracebacks etc. across sockets...my proposed
interface just seemed a little more general.
>
> How about this (just an idea):
>     def info(self, msgOrException, *args):
>         if isinstance(msgOrException, Exception):
>             # format the exception and
>             msg, args = args[0], args[1:]
>         else:
>             # treat it like before
>
>     try:
>         # ...
>     except Exception, ex:
>         log.info(ex, "Eeeeek!")
I have to admit I find these kinds of "special cases" worthy of caution. I'd
much rather provide a parallel set of xxxException() methods - I think they
would result in less "gotcha"s for the occasional (or inexperienced) user.
Plus - at some point we are going to have to think about performance - and
then we may regret overcomplicating the usual case code path for less common
scenarios.

Regards

Vinay