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.


✨ New Features

  • Automatic log saving: All logs are saved by default to a ./logs folder.
  • Timestamped log files: Each run creates a new log file named like interceptor_2025-09-07_17-15-30.log.
  • Custom log directory: Users can change the default log folder at runtime by calling set_log_directory("/path/to/logs").

📦 Installation

Install from PyPI:

pip install simple-logging-interceptor

🚀 Usage

from simple_logging_interceptor.decorators import simple_logging_interceptor, set_log_directory

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

@simple_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))

# Change log directory at runtime
set_log_directory("/tmp/custom_logs")
print(add(10, 20))

Example log output:

2025-09-07 17:15:30 - INFO - Calling: add with args=(2, 3), kwargs={}
2025-09-07 17:15:30 - INFO - Returned from add -> 5 (took 0.0021 ms)
2025-09-07 17:15:30 - INFO - Calling: greet with args=('Bob',), kwargs={'age': 30}
2025-09-07 17:15:30 - INFO - Returned from greet -> Hello Bob, you are 30 years old! (took 0.0043 ms)
2025-09-07 17:15:30 - INFO - Logging directory changed to: /tmp/custom_logs, file=interceptor_2025-09-07_17-15-30.log
2025-09-07 17:15:30 - INFO - Calling: add with args=(10, 20), kwargs={}
2025-09-07 17:15:30 - INFO - Returned from add -> 30 (took 0.0015 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.5.tar.gz (3.5 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.5-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for simple_logging_interceptor-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ee56431b74051f3a567e5a9a1058b089e7791a171a3c7ac7f90a1216d0620f98
MD5 ea041bf78f25224a4b6a07e8764c1f2f
BLAKE2b-256 1f5b38b0071c6f7817788d25bcc10a16fcc9fe14ac85fb6a002c38f6dcf18ae5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for simple_logging_interceptor-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 fd34de8a445dc4d7268843329e61b5a376adccd70949e20f1730ca397c5afb09
MD5 cab27d22b4e0df13d70c03fc1b824563
BLAKE2b-256 09196725ea06833a2e14db18a45b5a29c3f36b950695bde6ac831438a956b0fa

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