logwrap
logwrap is a helper for logging in human-readable format function arguments and call result on function call.
Pros:
Free software: Apache license
Open Source: https://github.com/penguinolog/logwrap
PyPI packaged: https://pypi.python.org/pypi/logwrap
Self-documented code: docstrings with types in comments
Tested: see bages on top
Support miltiple Python versions:
Python 2.7 Python 3.4 Python 3.5 Python 3.6 PyPy
This package also includes helpers:
pretty_repr
pretty_str
PrettyFormat
Usage
logwrap
The main decorator. Could be used as not argumented (@logwrap.logwrap) and argumented (@logwrap.logwrap()). Not argumented usage simple calls with default values for all positions. Argumented usage with arguments from signature:
@logwrap.logwrap(
log=logging.getLogger(__name__), # __name__ = 'logwrap'
log_level=logging.DEBUG,
exc_level=logging.ERROR,
max_indent=20, # forwarded to the pretty_repr
spec=None, # use target callable function for spec
)
Usage examples:
@logwrap.logwrap()
def foo():
pass
is equal to:
@logwrap.logwrap
def foo():
pass
Get decorator for use without parameters:
get_logs = logwap.logwrap() # set required parameters via arguments
@get_logs
def foo():
pass
Limitations: * return value from awaitable objects (async def(…) is not accessible - on call asyncio object is returned.
nested wrapping (@logwrap @deco2 …) is not parsed under python 2.7: funcsigs limitation. Please set logwrap as the first level decorator.
pretty_repr
This is specified helper for making human-readable repr on complex objects. Signature is self-documenting:
def pretty_repr(
src, # object for repr
indent=0, # start indent
no_indent_start=False, # do not indent the first level
max_indent=20, # maximum allowed indent level
indent_step=4, # step between indents
py2_str=False, # use bytes for python 2 __repr__ and __str__
)
Limitation: Dict like objects is always marked inside {} for readability, even if it is collections.OrderedDict (standard repr as list of tuples).
pretty_str
This is specified helper for making human-readable repr on complex objects. Signature is self-documenting:
def pretty_str(
src, # object for __str__
indent=0, # start indent
no_indent_start=False, # do not indent the first level
max_indent=20, # maximum allowed indent level
indent_step=4, # step between indents
py2_str=False, # use bytes for python 2 __repr__ and __str__
)
- Limitations:
Dict like objects is always marked inside {} for readability, even if it is collections.OrderedDict (standard repr as list of tuples). Iterable types is not declared, only brackets is used. String and bytes looks the same (its __str__, not __repr__).
PrettyFormat
PrettyFormat is the main formatting implementation class. on pretty_repr instance of this class is created and executed. Object signature:
def __init__(
self,
simple_formatters, # Will be used to repr not complex. Keys is data types and 'default'.
complex_formatters, # Currently only legacy pretty_repr formatters is supported, will be extended in the future
keyword='repr', # Currently 'repr' is supported, will be extended in the future
max_indent=20, # maximum allowed indent level
indent_step=4, # step between indents
py2_str=False, # use bytes for python 2 __repr__ and __str__
)
Callable object (PrettyFormat instance) signature:
def __call__(
self,
src, # object for repr
indent=0, # start indent
no_indent_start=False # do not indent the first level
)
Adopting your code
pretty_repr behavior could be overridden for your classes by implementing specific magic method:
def __pretty_repr__(
self,
parser # PrettyFormat class instance,
indent # start indent,
no_indent_start # do not indent the first level
):
return ...
This method will be executed instead of __repr__ on your object.
Testing
The main test mechanism for the package logwrap is using tox. Test environments available:
pep8 py27 py34 py35 pypy pylint docs
CI systems
For code checking several CI systems is used in parallel:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
coveralls: is used for coverage display.
CD system
Travis CI: is used for package delivery on PyPI.
Metadata
Release files for logwrap 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| logwrap-1.1.0.tar.gz | 19.0 kB | Without provenance | Details for logwrap-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logwrap-1.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for logwrap-1.1.0-py2.py3-none-any.whl |
Total release size: 32.6 kB
Release files / logwrap-1.1.0.tar.gz
| Download URL | logwrap-1.1.0.tar.gz |
|---|---|
| Size | 19.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24efd478eac714934c7e625d4ca6d342ad474880fb1da53232fcc9d878820f82
|
|
BLAKE2b-256 checksum How to use checksums |
d25ad51a110fd9b48a428bb52c8fddf5ac3bcee93e29a15a78559d9027b7aacb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / logwrap-1.1.0-py2.py3-none-any.whl
| Download URL | logwrap-1.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
820a677840abf3501d5f2e838efe32c86f90fd90bc289a1b7a89251f7a3b9522
|
|
BLAKE2b-256 checksum How to use checksums |
da8b41cd853fefd5328d91b9557a2776d05540bff11116e3f7a28e85ff8b1bef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for logwrap 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.