|
27 | 27 | import asyncio |
28 | 28 | import functools |
29 | 29 | import inspect |
30 | | -import logging |
31 | 30 | import typing |
32 | 31 |
|
33 | 32 |
|
|
36 | 35 | __all__ = ('logwrap', 'LogWrap') |
37 | 36 |
|
38 | 37 |
|
39 | | -DEFAULT_DECORATOR_ARGUMENT = typing.Union[logging.Logger, typing.Callable] |
40 | | - |
41 | | - |
42 | 38 | class LogWrap(_log_wrap_shared.BaseLogWrap): |
43 | 39 | """Python 3.3+ version of LogWrap.""" |
44 | 40 |
|
@@ -110,63 +106,4 @@ def wrapper(*args, **kwargs): |
110 | 106 | return async_wrapper if asyncio.iscoroutinefunction(func) else wrapper |
111 | 107 |
|
112 | 108 |
|
113 | | -# pylint: disable=unexpected-keyword-arg, no-value-for-parameter |
114 | | -def logwrap( |
115 | | - log: DEFAULT_DECORATOR_ARGUMENT = _log_wrap_shared.logger, |
116 | | - log_level: int = logging.DEBUG, |
117 | | - exc_level: int = logging.ERROR, |
118 | | - max_indent: int = 20, |
119 | | - spec: typing.Optional[typing.Callable] = None, |
120 | | - blacklisted_names: typing.Optional[typing.List[str]] = None, |
121 | | - blacklisted_exceptions: typing.Optional[typing.List[Exception]] = None, |
122 | | - log_call_args: bool = True, |
123 | | - log_call_args_on_exc: bool = True, |
124 | | - log_result_obj: bool = True, |
125 | | -) -> LogWrap: |
126 | | - """Log function calls and return values. Python 3.4+ version. |
127 | | -
|
128 | | - :param log: logger object for decorator, by default used 'logwrap' |
129 | | - :type log: typing.Union[logging.Logger, typing.Callable] |
130 | | - :param log_level: log level for successful calls |
131 | | - :type log_level: int |
132 | | - :param exc_level: log level for exception cases |
133 | | - :type exc_level: int |
134 | | - :param max_indent: maximum indent before classic `repr()` call. |
135 | | - :type max_indent: int |
136 | | - :param spec: callable object used as spec for arguments bind. |
137 | | - This is designed for the special cases only, |
138 | | - when impossible to change signature of target object, |
139 | | - but processed/redirected signature is accessible. |
140 | | - Note: this object should provide fully compatible signature |
141 | | - with decorated function, or arguments bind will be failed! |
142 | | - :type spec: typing.Optional[typing.Callable] |
143 | | - :param blacklisted_names: list of exception, |
144 | | - which should be re-raised without |
145 | | - producing log record. |
146 | | - :type blacklisted_names: typing.Optional[typing.Iterable[str]] |
147 | | - :param blacklisted_exceptions: list of exception, |
148 | | - which should be re-raised without |
149 | | - producing log record. |
150 | | - :type blacklisted_exceptions: typing.Optional[typing.Iterable[Exception]] |
151 | | - :param log_call_args: log call arguments before executing wrapped function. |
152 | | - :type log_call_args: bool |
153 | | - :param log_call_args_on_exc: log call arguments if exception raised. |
154 | | - :type log_call_args_on_exc: bool |
155 | | - :param log_result_obj: log result of function call. |
156 | | - :type log_result_obj: bool |
157 | | - :return: built real decorator. |
158 | | - :rtype: _log_wrap_shared.BaseLogWrap |
159 | | - """ |
160 | | - return LogWrap( |
161 | | - log=log, |
162 | | - log_level=log_level, |
163 | | - exc_level=exc_level, |
164 | | - max_indent=max_indent, |
165 | | - spec=spec, |
166 | | - blacklisted_names=blacklisted_names, |
167 | | - blacklisted_exceptions=blacklisted_exceptions, |
168 | | - log_call_args=log_call_args, |
169 | | - log_call_args_on_exc=log_call_args_on_exc, |
170 | | - log_result_obj=log_result_obj |
171 | | - ) |
172 | | -# pylint: enable=unexpected-keyword-arg, no-value-for-parameter |
| 109 | +logwrap = LogWrap # lowercase decorator |
0 commit comments