A simple Python decorator for logging function calls, arguments, return values, execution time, and exceptions.
Project description
Logging Interceptor
A simple Python decorator for logging function calls, arguments, return values, execution time, and exceptions.
Designed to be lightweight, reusable, and project-agnostic.
✨ Features
- Logs:
- Function name
- Arguments (
args,kwargs) - Return value
- Execution time (in ms)
- Exceptions (with traceback)
- Works across projects with minimal setup
- Compatible with Python 3.8+
📦 Installation
From PyPI (after publishing):
pip install logging-interceptor
Or install locally (development mode):
git clone https://github.com/yourusername/logging-interceptor.git
cd logging-interceptor
pip install -e .
🚀 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)) # Logs inputs, result, and timing
print(greet("Alice")) # Logs kwargs properly
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:
pip install -r requirements.txt
pytest tests/
Example success output:
✅ test_add passed
✅ test_divide passed
✅ test_divide_by_zero passed
✅ test_greet_with_kwargs passed
✅ test_greet_without_kwargs passed
📂 Project Structure
logging_interceptor/
│── __init__.py
│── decorators.py
tests/
│── test.py
setup.py
README.md
requirements.txt
📜 License
This project is licensed under the MIT License.
🤝 Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.
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 simple_logging_interceptor-0.1.1.tar.gz.
File metadata
- Download URL: simple_logging_interceptor-0.1.1.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9807711901c418f56ad2e5772a518e4e819d44792e7dab5bad966f5f1e90f5f1
|
|
| MD5 |
efa7c0e0f49dac399b5acd65924c8c40
|
|
| BLAKE2b-256 |
28637cde72b4c16d9a636fc5b2ae9225959dff6a0a227c6f563ca6ca7ef05de0
|
File details
Details for the file simple_logging_interceptor-0.1.1-py3-none-any.whl.
File metadata
- Download URL: simple_logging_interceptor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeefe75fa22dc6f84639058b280d2ab92ac92a596cd60783e99593ef2d49d193
|
|
| MD5 |
40753f0f8ecf887afe26d2b365a85fed
|
|
| BLAKE2b-256 |
ba9d1d0d47650b275cd940a4a57c9469c1574d214dc1602df1b20dbe9f2eac50
|