@@ -197,7 +197,11 @@ def exception(self, msg, *args, **kwargs):
197197 message, augmented by kwargs['where'] and exception.where
198198 attributes (contextual messages).
199199
200- If <msg> is not None, run as usual (logging.Logger.exception)
200+ If exc_info is given and it is an exception object, use
201+ that instead of the current caught exception.
202+
203+ If <msg> is not None nor empty,
204+ run as usual (logging.Logger.exception)
201205 '''
202206 exc_info = kwargs .pop ('exc_info' , True )
203207 where_default = kwargs .pop ('where' , None )
@@ -207,15 +211,19 @@ def exception(self, msg, *args, **kwargs):
207211 if where_default :
208212 msg += ' {where_default}'
209213
210- ex = sys .exc_info ()[1 ]
214+ if isinstance (exc_info , BaseException ):
215+ ex = exc_info
216+ else :
217+ ex = sys .exc_info ()[1 ]
218+
211219 where = getattr (ex , 'where' , None )
212220 if where :
213221 msg += ', {where}'
214222
215223 msg += ':'
216224 msg = msg .format (where_default = where_default , where = where )
217225
218- return self .error (msg , exc_info = True , ** kwargs )
226+ return self .error (msg , exc_info = exc_info , ** kwargs )
219227 else :
220228 return Logger .exception (
221229 self , msg , * args , exc_info = exc_info , ** kwargs
0 commit comments