Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 27 additions & 21 deletions doc/source/PrettyFormat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
:rtype: str


.. py:class:: PrettyFormat(max_indent=20, indent_step=4, py2_str=False, )
.. py:class:: PrettyFormat(object)

Designed for usage as __repr__ and __str__ replacement on complex objects

.. versionadded:: 1.0.2
.. versionchanged:: 3.0.1

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool

.. note:: Attributes is read-only

Expand Down Expand Up @@ -115,31 +117,35 @@ API: Helpers: `pretty_repr`, `pretty_str` and base class `PrettyFormat`.
:rtype: str


.. py:class:: PrettyRepr(max_indent=20, indent_step=4, py2_str=False, )
.. py:class:: PrettyRepr(PrettyFormat)

Designed for usage as __repr__ replacement on complex objects

.. versionadded:: 3.0.0
.. versionchanged:: 3.0.1

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool


.. py:class:: PrettyStr(max_indent=20, indent_step=4, py2_str=False, )
.. py:class:: PrettyStr(PrettyFormat)

Designed for usage as __repr__ replacement on complex objects

.. versionadded:: 3.0.0
.. versionchanged:: 3.0.1

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
.. py:method:: __init__(max_indent=20, indent_step=4, py2_str=False, )

:param max_indent: maximal indent before classic repr() call
:type max_indent: int
:param indent_step: step for the next indentation level
:type indent_step: int
:param py2_str: use Python 2.x compatible strings instead of unicode
:type py2_str: bool
62 changes: 32 additions & 30 deletions doc/source/logwrap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,43 @@ API: Decorators: `LogWrap` class and `logwrap` function.
.. py:module:: logwrap
.. py:currentmodule:: logwrap

.. py:class:: LogWrap(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_result_obj=True, )
.. py:class:: LogWrap(object)

Log function calls and return values.

.. versionadded:: 2.2.0

:param log: logger object for decorator, by default used 'logwrap'
:type log: typing.Union[logging.Logger, typing.Callable]
:param log_level: log level for successful calls
:type log_level: int
:param exc_level: log level for exception cases
:type exc_level: int
:param max_indent: maximum indent before classic `repr()` call.
:type max_indent: int
:param spec: 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!
:type spec: typing.Optional[typing.Callable]
:param blacklisted_names: Blacklisted argument names.
Arguments with this names will be skipped in log.
:type blacklisted_names: typing.Optional[typing.Iterable[str]]
:param blacklisted_exceptions: list of exception,
which should be re-raised without
producing log record.
:type blacklisted_exceptions: typing.Optional[typing.Iterable[Exception]]
:param log_call_args: log call arguments before executing wrapped function.
:type log_call_args: bool
:param log_call_args_on_exc: log call arguments if exception raised.
:type log_call_args_on_exc: bool
:param log_result_obj: log result of function call.
:type log_result_obj: bool
.. py:method:: __init__(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_result_obj=True, )

:param log: logger object for decorator, by default used 'logwrap'
:type log: typing.Union[logging.Logger, typing.Callable]
:param log_level: log level for successful calls
:type log_level: int
:param exc_level: log level for exception cases
:type exc_level: int
:param max_indent: maximum indent before classic `repr()` call.
:type max_indent: int
:param spec: 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!
:type spec: typing.Optional[typing.Callable]
:param blacklisted_names: Blacklisted argument names.
Arguments with this names will be skipped in log.
:type blacklisted_names: typing.Optional[typing.Iterable[str]]
:param blacklisted_exceptions: list of exception,
which should be re-raised without
producing log record.
:type blacklisted_exceptions: typing.Optional[typing.Iterable[Exception]]
:param log_call_args: log call arguments before executing wrapped function.
:type log_call_args: bool
:param log_call_args_on_exc: log call arguments if exception raised.
:type log_call_args_on_exc: bool
:param log_result_obj: log result of function call.
:type log_result_obj: bool

.. note:: Attributes/properties names the same as argument names and changes
the same fields.
Expand Down
6 changes: 3 additions & 3 deletions logwrap/_class_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import abc
import functools
import sys
import typing
import typing # noqa # pylint: disable=unused-import

PY3 = sys.version_info[:2] > (3, 0)


class BaseDecorator(typing.Callable):
class BaseDecorator(object):
"""Base class for decorators.

Implements wrapping and __call__, wrapper getter is abstract.
Expand All @@ -33,7 +33,7 @@ class BaseDecorator(typing.Callable):
def __init__(
self,
func=None # type: typing.Optional[typing.Callable]
):
): # type: (...) -> None
"""Decorator.

:param func: function to wrap
Expand Down
3 changes: 1 addition & 2 deletions logwrap/_log_wrap_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def __init__(
log_call_args=True, # type: bool
log_call_args_on_exc=True, # type: bool
log_result_obj=True, # type: bool

):
): # type: (...) -> None
"""Log function calls and return values.

:param log: logger object for decorator, by default used 'logwrap'
Expand Down
2 changes: 1 addition & 1 deletion logwrap/_repr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def __init__(
max_indent=20, # type: int
indent_step=4, # type: int
py2_str=False, # type: bool
):
): # type: (...) -> None
"""Pretty Formatter.

:param max_indent: maximal indent before classic repr() call
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
# Minimum requirements for the build system to execute.
# PEP 508 specifications for PEP 518.
requires = [
"setuptools > 20.2 ",
"wheel",
]