API: Decorators: LogWrap class and logwrap function.

class logwrap.LogWrap(object)[source]

Log function calls and return values.

New in version 2.2.0.

__init__(func=None, *, log=logging.getLogger('logwrap'), log_level=logging.DEBUG, exc_level=logging.ERROR, max_indent=20, spec=None, blacklisted_names=None, blacklisted_exceptions=None, log_call_args=True, log_call_args_on_exc=True, log_traceback=True, log_result_obj=True)[source]
  • func (typing.Optional[typing.Callable]) – function to wrap
  • log (logging.Logger) – logger object for decorator, by default used ‘logwrap’
  • log_level (int) – log level for successful calls
  • exc_level (int) – log level for exception cases
  • max_indent (int) – maximum indent before classic repr() call.
  • spec (typing.Optional[typing.Callable]) – callable object used as spec for arguments bind. This is designed for the special cases only, when impossible to change signature of target object, but processed/redirected signature is accessible. Note: this object should provide fully compatible signature with decorated function, or arguments bind will be failed!
  • blacklisted_names (typing.Optional[typing.Iterable[str]]) – Blacklisted argument names. Arguments with this names will be skipped in log.
  • blacklisted_exceptions (typing.Optional[typing.Iterable[typing.Type[Exception]]]) – list of exception, which should be re-raised without producing log record.
  • log_call_args (bool) – log call arguments before executing wrapped function.
  • log_call_args_on_exc (bool) – log call arguments if exception raised.
  • log_traceback (bool) – log traceback on excaption in addition to failure info
  • log_result_obj (bool) – log result of function call.

Changed in version 3.3.0: Extract func from log and do not use Union.

Changed in version 3.3.0: Deprecation of *args

Changed in version 4.0.0: Drop of *args

Changed in version 5.1.0: log_traceback parameter

pre_process_param(self, arg)[source]

Process parameter for the future logging.

Parameters:arg (BoundParameter) – bound parameter
Returns:value, value override for logging or None if argument should not be logged.
Return type:typing.Union[BoundParameter, typing.Tuple[BoundParameter, typing.Any], None]

Override this method if some modifications required for parameter value before logging

New in version 3.3.0.

post_process_param(self, arg, arg_repr)[source]

Process parameter for the future logging.

  • arg (BoundParameter) – bound parameter
  • arg_repr (typing.Text) – repr for value

processed repr for value

Return type:


Override this method if some modifications required for result of repr() over parameter

New in version 3.3.0.


Attributes/properties names the same as argument names and changes the same fields.


typing.List[str], modified via mutability


typing.List[typing.Type[Exception]], modified via mutability


typing.Optional[typing.Callable[..., typing.Awaitable]] Wrapped function. Used for inheritance only.

__call__(*args, **kwargs)[source]

Decorator entry-point. Logic is stored separately and load depends on python version.

Returns:Decorated function. On python 3.3+ awaitable is supported.
Return type:typing.Union[typing.Callable, typing.Awaitable]
class logwrap.BoundParameter(inspect.Parameter)[source]

Parameter-like object store BOUND with value parameter. .. versionchanged:: 5.3.1 subclass inspect.Parameter

New in version 3.3.0.

__init__(self, parameter, value=Parameter.empty)[source]

Parameter-like object store BOUND with value parameter.

  • parameter (inspect.Parameter) – parameter from signature
  • value (typing.Any) – parameter real value

ValueError – No default value and no value


Parameter object.

Return type:BoundParameter

Parameter value.

Return type:typing.Any

String representation.

Return type:str
logwrap.bind_args_kwargs(sig, *args, **kwargs)[source]

Bind *args and **kwargs to signature and get Bound Parameters.

Parameters:sig (inspect.Signature) – source signature
Returns:Iterator for bound parameters with all information about it
Return type:typing.List[BoundParameter]

New in version 3.3.0.

Changed in version 5.3.1: return list