Simple, useful decorators for logging and tallying function calls
Project description
funlog
funlog is a tiny but quite useful package that offers a few Python decorators to log
function calls, with good control over what gets logged and when.
It also times the function call and logs arguments briefly but clearly, abbreviating
arguments like long strings or dataclasses.
It is fully customizable with optional decorator arguments. You can log only slow calls, only if a function modifies its first argument, or tally calls and log them later.
I'm publishing it standalone since I often like to drop this into projects and it simplifies print-debugging a lot of things or lets you do very lightweight profiling where get logs if certain functions are taking a lot of time, or tallies of function calls after a program runs a while or at exit.
Minimal dependencies (only the tiny strif).
Installation
pip install funlog
Usage
Suppose you have a few functions:
import time
import logging
from funlog import log_calls, log_if_modifies, log_tallies, tally_calls
logging.basicConfig(
level=logging.DEBUG,
format="%(levelname)s:%(message)s",
force=True,
)
@log_calls()
def add(a, b):
return a + b
@log_calls(level="warn", if_slower_than=0.1, show_return_value=False)
def slow_function(delay):
time.sleep(delay)
return f"Slept for {delay} seconds"
# Now call the functions.
add(2, 3)
slow_function(0.5)
Running that gives you:
INFO:≫ Call: __main__.add(2, 3)
INFO:≪ Call done: __main__.add() took 0.00ms: 5
WARNING:⏱ Call to __main__.slow_function(0.5) took 503ms
See test_examples.py for more examples and docstrings for more docs on all the options.
This project was built from simple-modern-poetry.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file funlog-0.1.0.tar.gz.
File metadata
- Download URL: funlog-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
565f1dfac984e5638441ea1a6c53a303b417313808f7335e994bce318dcf93a6
|
|
| MD5 |
b8fdf974f359e480e80a56fdc3706637
|
|
| BLAKE2b-256 |
d75e37e8e8d9422ede20fbf0b2249c5f639e0ad9a2572b11ee9251caf3104f1a
|
Provenance
The following attestation bundles were made for funlog-0.1.0.tar.gz:
Publisher:
publish.yml on jlevy/funlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
funlog-0.1.0.tar.gz -
Subject digest:
565f1dfac984e5638441ea1a6c53a303b417313808f7335e994bce318dcf93a6 - Sigstore transparency entry: 175264261
- Sigstore integration time:
-
Permalink:
jlevy/funlog@e80220f6aac0200151dadaf0e29f486aa3ef6256 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jlevy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e80220f6aac0200151dadaf0e29f486aa3ef6256 -
Trigger Event:
release
-
Statement type:
File details
Details for the file funlog-0.1.0-py3-none-any.whl.
File metadata
- Download URL: funlog-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c1335a0f100547026bd18e02cc59d96f56ae7387e3917fc91f9b5f71fede0ed
|
|
| MD5 |
60590e5f0a7bc91f478d5c0e6c1f2553
|
|
| BLAKE2b-256 |
a317018d759256587dfcb1a19d52a944925840ffafedcef484d7d8eeea2e41ae
|
Provenance
The following attestation bundles were made for funlog-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on jlevy/funlog
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
funlog-0.1.0-py3-none-any.whl -
Subject digest:
6c1335a0f100547026bd18e02cc59d96f56ae7387e3917fc91f9b5f71fede0ed - Sigstore transparency entry: 175264265
- Sigstore integration time:
-
Permalink:
jlevy/funlog@e80220f6aac0200151dadaf0e29f486aa3ef6256 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jlevy
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e80220f6aac0200151dadaf0e29f486aa3ef6256 -
Trigger Event:
release
-
Statement type: