Skip to main content

A simple Python decorator for logging function calls, arguments, return values, execution time, and exceptions.

Project description

Logging Interceptor

A lightweight Python decorator for logging function calls, arguments, return values, execution time, and exceptions.
Designed to be simple, reusable, and project-agnostic.


📦 Installation

Install from PyPI:

pip install logging-interceptor

🚀 Usage

from logging_interceptor.decorators import logging_interceptor


@logging_interceptor
def add(a, b):
    return a + b


@logging_interceptor
def greet(name, age=None):
    if age:
        return f"Hello {name}, you are {age} years old!"
    return f"Hello {name}!"


print(add(2, 3))
print(greet("Alice"))
print(greet("Bob", age=30))

Example log output:

2025-09-07 12:01:00,123 - INFO - Calling: add with args=(2, 3), kwargs={}
2025-09-07 12:01:00,124 - INFO - Returned from add -> 5 (took 0.01 ms)
2025-09-07 12:01:00,125 - INFO - Calling: greet with args=('Bob',), kwargs={'age': 30}
2025-09-07 12:01:00,125 - INFO - Returned from greet -> Hello Bob, you are 30 years old! (took 0.02 ms)

🧪 Running Tests

This project uses pytest.
To run tests locally:

pip install pytest
pytest

📜 License

This project is licensed under the MIT License.

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

simple_logging_interceptor-0.1.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

simple_logging_interceptor-0.1.2-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for simple_logging_interceptor-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2f817f6b8a9d13923201ad1609bda5c789ebd591697a36d840611175c753e5e4
MD5 06f2ac3f8eeabe72db2c5b42d8e7c1ef
BLAKE2b-256 657b084941eeaee0f021968704ceb69881965929353ab1bbe43883d8606a9820

See more details on using hashes here.

File details

Details for the file simple_logging_interceptor-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for simple_logging_interceptor-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1746dfd2ea64010c7c3bf6688b90d4939f09df9de8c0063d3ae20fc79555b235
MD5 6b87cf3b297de76857aa805963c9b618
BLAKE2b-256 b7ef36db822eec96388941bc1aee587c59d74519637b39d9ab38e9558ef9707f

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