[Python-Dev] Fw: logging exceptions

Vinay Sajip vinay_sajip at yahoo.co.uk
Fri Feb 20 03:11:13 EST 2004


----- Original Message -----
From: "Vinay Sajip" <vinay_sajip at red-dove.com>
To: <python-dev at python.org>
Cc: <jeremy at alum.mit.edu>
Sent: Friday, February 20, 2004 12:25 AM
Subject: Re: logging exceptions


> > Zope 2.7 is using the logging package internally as the implementation
> > for its old zLOG API.  We've run into one problem, probably caused by
> > carelessness on our part.
> >
> > zLOG allows you to pass exc_info to be logged, but logging only allows
> > you to specify a flag saying whether the current exception should be
> > logged.  (I recall that this was discussed at length, but not why the
> > current solution was reached.)  There are several call sites that depend
> > on this feature to capture an exception, try to recover gracefully or
> > log a traceback if recovery is impossible.  So we depend on this
> > feature, but can't get it out of logging very easily.
> >
> > We've come up with this as a work-around:
> ["Gross" workaround snipped]
>
> I propose to make the following change:
>      def _log(self, level, msg, args, exc_info=None):
>          # ...
>          if exc_info:
>            if type(exc_info) != types.TupleType:
>              exc_info = sys.exc_info()
>          record = self.makeRecord(self.name, level, fn, lno, msg, args,
> exc_info)
>          self.handle(record)
>
> This should allow passing an exception tuple in the exc_info parameter -
in
> which case, that's used instead of calling sys.exc_info(). It is a slight
> change to the semantics but I can't think of any (non-pathological) code
> which will break. Can anyone see any problems with this approach?
>
> Regards,
>
> Vinay
>




More information about the Python-Dev mailing list