Skip to main content

Toolkit for responsible, low-boilerplate logging of library method calls

Project description

Logfury is for python library maintainers. It allows for responsible, low-boilerplate logging of method calls.

License

BSD 3-clause

whats with the weird import

from logfury.v0_1 import DefaultTraceMeta

If you were to use logfury in your library, any change to the API could potentially break your program. Nobody wants that.

Thanks to this import trick I can keep the 0.1.x API very stable. At the same time I can change the functionality of the library and change default behavior of version 0.2.x etc, without changing the name of the package. This way YOU decide when to adopt potentially incompatible API changes, by incrementing the API version on import.

Installation

Current stable

pip install logfury

Development version

git clone git@github.com:ppolewicz/logfury.git
python setup.py install

Basic usage

DefaultTraceMeta metaclass

>>> import logging
>>> import six
>>>
>>> from logfury.v0_1 import DefaultTraceMeta, limit_trace_arguments, disable_trace
>>>
>>>
>>> logging.basicConfig()
>>> logger = logging.getLogger(__name__)
>>> logger.setLevel(logging.DEBUG)
>>>
>>>
>>> @six.add_metaclass(DefaultTraceMeta)
>>> class Foo(object):
...     def baz(self, a, b, c=None):
...         return True
...     def get_blah(self):
...         return 5
...     def _hello(self):
...         pass
...     @disable_trace
...     def world(self):
...         pass
...     def __repr__(self):
...         return '<%s object>' % (self.__class__.__name__,)
...
>>> class Bar(Foo):
...     def baz(self, a, b, c=None):
...         b += 1
...         return super(Bar, self).baz(a, b, c)
...     def world(self):
...         pass
...     @limit_trace_arguments(skip=['password'])
...     def secret(self, password, other):
...         pass
...     @limit_trace_arguments(only=['other'])
...     def secret2(self, password, other):
...         pass
...
>>> a = Foo()
>>> a.baz(1, 2, 3)
DEBUG:__main__:calling Foo.baz(self=<Foo object>, a=1, b=2, c=3)
>>> a.baz(4, b=8)
DEBUG:__main__:calling Foo.baz(self=<Foo object>, a=4, b=8)
>>> a.get_blah()  # nothing happens, since v0_1.DefaultTraceMeta does not trace "get_.*"
>>> a._hello()  # nothing happens, since v0_1.DefaultTraceMeta does not trace "_.*"
>>> a.world()  # nothing happens, since v0_1.DefaultTraceMeta does not trace "_.*"
>>> b = Bar()
>>> b.baz(4, b=8)  # tracing is inherited
DEBUG:__main__:calling Bar.baz(self=<Bar object>, a=4, b=8)
DEBUG:__main__:calling Foo.baz(self=<Bar object>, a=4, b=9, c=None)
>>> b.world()  # nothing happens, since Foo.world() tracing was disabled and Bar inherited it
>>> b.secret('correct horse battery staple', 'Hello world!')
DEBUG:__main__:calling Bar.secret(self=<Bar object>, other='Hello world!') (hidden args: password)
>>> b.secret2('correct horse battery staple', 'Hello world!')
DEBUG:__main__:calling Bar.secret2(other='Hello world!') (hidden args: self, password)

trace_call decorator

>>> import logging
>>> from logfury import *
>>> logging.basicConfig()
>>> logger = logging.getLogger(__name__)
>>>
>>> @trace_call(logger)
... def foo(a, b, c=None):
...     return True
...
>>> foo(1, 2, 3)
True
>>> logger.setLevel(logging.DEBUG)
>>> foo(1, 2, 3)
DEBUG:__main__:calling foo(a=1, b=2, c=3)
True
>>> foo(1, b=2)
DEBUG:__main__:calling foo(a=1, b=2)
True
>>>

Project details


Download files

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

Source Distribution

logfury-0.1.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logfury-0.1.2-py2.py3-none-any.whl (12.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file logfury-0.1.2.tar.gz.

File metadata

  • Download URL: logfury-0.1.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for logfury-0.1.2.tar.gz
Algorithm Hash digest
SHA256 42da58fbbd4e6fdb9e5b6b9098e94c249ba9cebfae125643329c8636768edcd3
MD5 b1bc3990bbb6c426e36bdb2d3da09e7d
BLAKE2b-256 e2a066a7b78e1800af85e54701490cf8764cc6de6c0725d18b10a6fb13ce4d2d

See more details on using hashes here.

File details

Details for the file logfury-0.1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for logfury-0.1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e0ce7f95bab6e5b2fd835b3d8ff5e226704476671d15340a99b00285f4c2d1fc
MD5 f189f6d0d2ea774382f3e566d4896eb2
BLAKE2b-256 5571c70df1ef41721b554c91982ebde423a5cf594261aa5132e39ade9196fa3b

See more details on using hashes here.

Supported by

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