Skip to main content

Decorator for logging function arguments by human-readable way

Project description

logwrap

https://travis-ci.org/penguinolog/logwrap.svg?branch=master https://img.shields.io/circleci/project/github/penguinolog/logwrap.svg https://api.codacy.com/project/badge/Grade/72f332d53b924cd2b2c0dc6f9d1f8d0f https://api.codacy.com/project/badge/Coverage/72f332d53b924cd2b2c0dc6f9d1f8d0f https://img.shields.io/pypi/v/logwrap.svg https://img.shields.io/pypi/pyversions/logwrap.svg https://img.shields.io/pypi/status/logwrap.svg https://img.shields.io/github/license/penguinolog/logwrap.svg

logwrap is a helper for logging in human-readable format function arguments and call result on function call.

Pros:

Python 2.7
Python 3.4
Python 3.5
Python 3.6
PyPy

This package also includes helpers:

  • pretty_repr

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

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
)

Limitation: Dict like objects is always marked inside {} for readability, even if it is collections.OrderedDict (standard repr as list of tuples).

Testing

The main test mechanism for the package logwrap is using tox. Test environments available:

pep8
py27
py34
py35
pypy
pylint
docs

Also possible to run python setup.py test for unit tests and python setup.py flake8 for code style tests, but it requires all package dependencies to be installed.

CI systems

For code checking several CI systems is used in parallel:

  1. Travis CI: is used for checking: PEP8, installation possibility and unit tests

  2. Circle CI: is used for checking: pylint, docs. In addition this CI publishes coverage results.

  3. Codacy: is used for statical analysis and coverage display.

CD system

Travis CI: is used for package delivery on PyPI.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logwrap-1.0.0.tar.gz (15.1 kB view hashes)

Uploaded Source

Built Distribution

logwrap-1.0.0-py2.py3-none-any.whl (10.6 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page