logging exceptions

Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Aug 27 09:30:25 EDT 2008


On Aug 27, 10:30 am, Rob Wolfe <r... at smsnet.pl> wrote:
> Vinay Sajip napisa³(a):
>
>
>
> > On Aug 26, 10:36 am, Alexandru  Mosoi <brtz... at gmail.com> wrote:
> > > why doesn'tloggingthrow any exception when it should? how do I
> > > configureloggingto throw exceptions?
>
> > > >>> try:
>
> > > ...  logging.fatal('asdf %d', '123')
> > > ... except:
> > > ...   print 'this line is never printed'
> > > ...
> > > Traceback (most recent call last):
> > >   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> > > python2.5/logging/__init__.py", line 744, in emit
> > >     msg = self.format(record)
> > >   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> > > python2.5/logging/__init__.py", line 630, in format
> > >     return fmt.format(record)
> > >   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> > > python2.5/logging/__init__.py", line 418, in format
> > >     record.message = record.getMessage()
> > >   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
> > > python2.5/logging/__init__.py", line 288, in getMessage
> > >     msg = msg % self.args
> > > TypeError: int argument required
>
> > Was your traceback from the snippet you posted? If it was, then the
> > exception (a TypeError) *is* being raised fromlogging. So I don't
> > understand your question "why doesn'tloggingthrow any exception when
> > it should?", becauseloggingis raising an exception here.
>
> No, it isn't.
> This traceback is *printed* in `Handler.handleError` method:
>

You're right - silly me. I wasn't paying attention :-(

> > variable would normally be set to 0 in a production environment, where
> > you don't wantlogging-related exceptions to bring an application
> > down.
>
> Well, I think that it will not help. The exception will be printed
> not raised. The only solution is to redefine `handleError` method
> or maybe I've missed something?
>


No, you're right. To do custom handling of exceptions, handleError
needs to be overridden.

Regards,

Vinay



More information about the Python-list mailing list