Logfury
Logfury is a tool for python library maintainers. It allows for responsible, low-boilerplate logging of method calls.
whats with the weird import
from logfury.v1 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 API very stable. At the same time I can change the functionality of the library and change default behavior of next middle version, 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. This concept is called “apiver”.
Installation
Current stable
pip install logfury
Development version
git clone git@github.com:reef-technologies/logfury.git pip install -e .
Basic usage
DefaultTraceMeta metaclass
>>> import logging
>>> import six
>>>
>>> from logfury.v1 import DefaultTraceMeta, limit_trace_arguments, disable_trace
>>>
>>>
>>> logging.basicConfig()
>>> logger = logging.getLogger(__name__)
>>> logger.setLevel(logging.DEBUG)
>>>
>>>
>>> @six.add_metaclass(DefaultTraceMeta)
>>> class Foo:
... 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 '<{} object>'.format(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 v1.DefaultTraceMeta does not trace "get_.*"
>>> a._hello() # nothing happens, since v1.DefaultTraceMeta does not trace "_.*"
>>> a.world() # nothing happens, since v1.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
>>>
Metadata
Release files for logfury 1.0.1
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 |
|---|---|---|---|---|
| logfury-1.0.1.tar.gz | 12.8 kB | Without provenance | Details for logfury-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| logfury-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for logfury-1.0.1-py3-none-any.whl |
Total release size: 20.3 kB
Release files / logfury-1.0.1.tar.gz
| Download URL | logfury-1.0.1.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
130a5daceab9ad534924252ddf70482aa2c96662b3a3825a7d30981d03b76a26
|
|
BLAKE2b-256 checksum How to use checksums |
90f224389d99f861dd65753fc5a56e2672339ec1b078da5e2f4b174d0767b132
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
|
Release files / logfury-1.0.1-py3-none-any.whl
| Download URL | logfury-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4f04be1701a1df644afc3384d6167d64c899f8036b7eefc3b6c570c6a9b290b
|
|
BLAKE2b-256 checksum How to use checksums |
04c78a2cfdf39f4cbbb307603aeb03ca89a4765b96be310a0848b20eb4d17e76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
|
Security for logfury 1.0.1
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.