@@ -188,7 +188,8 @@ def __init__(
188188 :type spec: typing.Optional[typing.Callable]
189189 :param blacklisted_names: Blacklisted argument names. Arguments with this names will be skipped in log.
190190 :type blacklisted_names: typing.Optional[typing.Iterable[str]]
191- :param blacklisted_exceptions: list of exception, which should be re-raised without producing log record.
191+ :param blacklisted_exceptions: list of exception, which should be re-raised
192+ without producing traceback and text log record.
192193 :type blacklisted_exceptions: typing.Optional[typing.Iterable[typing.Type[Exception]]]
193194 :param log_call_args: log call arguments before executing wrapped function.
194195 :type log_call_args: bool
@@ -297,7 +298,7 @@ def blacklisted_names(self) -> typing.List[str]:
297298
298299 @property
299300 def blacklisted_exceptions (self ) -> typing .List [typing .Type [Exception ]]:
300- """List of exceptions to re-raise without log.
301+ """List of exceptions to re-raise without log traceback and text .
301302
302303 :rtype: typing.List[typing.Type[Exception]]
303304 """
@@ -535,11 +536,12 @@ def _make_calling_record(self, name: str, arguments: str, method: str = "Calling
535536 """
536537 self ._logger .log (level = self .log_level , msg = f"{ method } : \n { name } ({ arguments if self .log_call_args else '' } )" )
537538
538- def _make_exc_record (self , name : str , arguments : str ) -> None :
539+ def _make_exc_record (self , name : str , arguments : str , exception : Exception ) -> None :
539540 """Make log record if exception raised.
540541
541542 :type name: str
542543 :type arguments: str
544+ :type exception: Exception
543545 """
544546 exc_info = sys .exc_info ()
545547 stack : traceback .StackSummary = traceback .extract_stack ()
@@ -548,15 +550,13 @@ def _make_exc_record(self, name: str, arguments: str) -> None:
548550 # Make standard traceback string
549551 tb_text : str = (
550552 f"Traceback (most recent call last):\n { '' .join (traceback .format_list (full_tb ))} { '' .join (exc_line )} "
553+ if self .log_traceback and not isinstance (exception , tuple (self .blacklisted_exceptions ))
554+ else exception .__class__ .__name__
551555 )
552556
553557 self ._logger .log (
554558 level = self .exc_level ,
555- msg = (
556- f"Failed: \n "
557- f"{ name } ({ arguments if self .log_call_args_on_exc else '' } )\n "
558- f"{ tb_text if self .log_traceback else '' } "
559- ),
559+ msg = f"Failed: \n { name } ({ arguments if self .log_call_args_on_exc else '' } )\n { tb_text } " ,
560560 exc_info = False ,
561561 )
562562
@@ -579,10 +579,8 @@ async def async_wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
579579 self ._make_calling_record (name = func .__name__ , arguments = args_repr , method = "Awaiting" )
580580 result = await func (* args , ** kwargs )
581581 self ._make_done_record (func .__name__ , result )
582- except BaseException as e :
583- if isinstance (e , tuple (self .blacklisted_exceptions )):
584- raise
585- self ._make_exc_record (name = func .__name__ , arguments = args_repr )
582+ except Exception as e :
583+ self ._make_exc_record (name = func .__name__ , arguments = args_repr , exception = e )
586584 raise
587585 return result # type: ignore
588586
@@ -596,10 +594,8 @@ def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
596594 self ._make_calling_record (name = func .__name__ , arguments = args_repr )
597595 result = func (* args , ** kwargs )
598596 self ._make_done_record (func .__name__ , result )
599- except BaseException as e :
600- if isinstance (e , tuple (self .blacklisted_exceptions )):
601- raise
602- self ._make_exc_record (name = func .__name__ , arguments = args_repr )
597+ except Exception as e :
598+ self ._make_exc_record (name = func .__name__ , arguments = args_repr , exception = e )
603599 raise
604600 return result
605601
@@ -715,7 +711,8 @@ def logwrap( # noqa: F811
715711 :type spec: typing.Optional[typing.Callable]
716712 :param blacklisted_names: Blacklisted argument names. Arguments with this names will be skipped in log.
717713 :type blacklisted_names: typing.Optional[typing.Iterable[str]]
718- :param blacklisted_exceptions: list of exceptions, which should be re-raised without producing log record.
714+ :param blacklisted_exceptions: list of exceptions, which should be re-raised
715+ without producing traceback and text log record.
719716 :type blacklisted_exceptions: typing.Optional[typing.Iterable[typing.Type[Exception]]]
720717 :param log_call_args: log call arguments before executing wrapped function.
721718 :type log_call_args: bool
0 commit comments