Skip to main content

Log entry and exit of methods with a decorator

Project description

methodlogger

methodlogger is a lightweight Python decorator that logs the entry and exit of methods or functions. It is ideal for debugging, performance tracing, and audit logging in both standalone Python projects.


📦 Installation

pip3 install methodlogger
(or use `pip` if it's already mapped to Python 3)

🚀 What Does It Do?

The @log_method decorator wraps any function or method and:

  • Logs when it enters and exits.
  • Supports custom log messages.
  • Includes timestamp logging (optional).
  • Uses Python’s logging module — works with any existing log setup.
  • Fully configurable, and supports external integration (JSON config, etc.)

✅ Features

  • 🧩 Plug-and-play decorator
  • 📃 Optional custom message per method
  • ⏱ Show timestamps in logs
  • ⚙️ Globally configurable via log_config

🔧 Configuration (log_config)

The decorator reads configuration from a central dictionary:

from methodlogger import log_config

log_config["enabled"] = True                      # Enable/disable all logging
log_config["default_message"] = "Executing"       # Fallback message if none provided
log_config["log_level"] = "INFO"                  # Log level (INFO, DEBUG, etc.)
log_config["show_time"] = True                    # Show timestamps in log

💡 Use Cases

  • Debugging production code

  • Tracking performance

  • Building audit logs

  • Understanding 3rd-party library behavior


🧪 Basic Example

from methodlogger.decorators import log_method

@log_method("Processing say_hello()")
def say_hello():
    print("Hello!")

say_hello()

[2025-06-23 14:10:12] Entering: say_hello - Processing say_hello()
Hello!
[2025-06-23 14:10:12] Exiting : say_hello - Processing say_hello()

You can also use it with no arguments:

@log_method()
def compute():
    return 42

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

methodlogger-0.1.2.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

methodlogger-0.1.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: methodlogger-0.1.2.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for methodlogger-0.1.2.tar.gz
Algorithm Hash digest
SHA256 109039f2cae32874d9da0e3660b54c854fb284a38a1ddd3d11131c9fc8e2d699
MD5 593f583799092369eb0a2657a2d0a884
BLAKE2b-256 42dc607cca4a9e8d96b81e5869f36bac6c010ed16b69b418e0d7c5d75fec2158

See more details on using hashes here.

File details

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

File metadata

  • Download URL: methodlogger-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for methodlogger-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7c231cbfd4c25851fccb10f50a8b422c3528a2e8bb992fc6b341913549d3e155
MD5 19a59c9d50cab98ea0d796faf6146333
BLAKE2b-256 2961b3af770f031d2fd26acb1e38c95f888741caf854af2e13df138e5050d0d3

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