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 and frameworks like Odoo.


📦 Installation

pip install methodlogger

🚀 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 (Odoo, JSON config, etc.)

✅ Features

  • 🧩 Plug-and-play decorator
  • 📃 Optional custom message per method
  • ⏱ Show timestamps in logs
  • ⚙️ Globally configurable via log_config
  • 🧠 Clean integration with Odoo’s logging and startup 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.1.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.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: methodlogger-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 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.1.tar.gz
Algorithm Hash digest
SHA256 74e15eee2f23497ef9e114746f73e60cca44ffd45912d4d2cd19dcd307daba42
MD5 393da0a753f967807ecca458b534185a
BLAKE2b-256 7f13ab33cfe5271d61363359ecf8aff4b41dc647a1157eab098512eaad7426af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: methodlogger-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f7618e5f78c60dae35a08580ac223112fe4e4cebea10489e7c96523bbbbc503
MD5 e14ebcca1fdba3b2979b4c6dea0244cb
BLAKE2b-256 76b4e7c72ddbe5dec7000cf01b94a3449fefdab3e3c3b667156c0e248d783b07

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