Skip to main content

Python debug logging helpers

Project description

debug_this

Package Status Documentation Status License Status Build Status Quality Status

Python debug logging helpers

Installation

Using pip:

pip install debug_this

Usage

The debug_this module export some decorators that can be used to debug your fucking code:

  • @debug_this.fucking_function To be used on those fucking functions that do not want to work as expected.
  • @debug_this.fucking_class To be used on fucking classes that are... Well you know!

All these decorators can be used with or without arguments or keywords arguments.

The available arguments are:

  • logger (logging.Logger, optional) Specify a logger instead of the default one.
  • print_parent (bool, optional) Print which function has called the decorated function.

Example

from __future__ import annotations

import logging

import debug_this

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)

@debug_this.fucking_function(print_parent=True)
def example_function() -> None:
    logger.info("This is an example function")

@debug_this.fucking_class(logger)
class ExampleClass:
    def __init__(self) -> None:
        logger.info("This is an example class constructor")
        ExampleClass.example_static_method(self)

    def example_method(self) -> None:
        logger.info("This is an example class method")
        example_function()

    @staticmethod
    def example_static_method(cls: ExampleClass) -> None:
        logger.info("This is an example class static method")
        cls.example_method()

if __name__ == "__main__":
    ExampleClass()

The resulting logs should look like this:

DEBUG:__main__:  >>> ExampleClass.__init__
INFO:__main__:This is an example class constructor
DEBUG:__main__:    >>> ExampleClass.example_static_method
INFO:__main__:This is an example class static method
DEBUG:__main__:      >>> ExampleClass.example_method
INFO:__main__:This is an example class method
DEBUG:debug_this:        >>> example_function (parent: example_method)
INFO:__main__:This is an example function
DEBUG:debug_this:        <<< example_function
DEBUG:__main__:      <<< ExampleClass.example_method
DEBUG:__main__:    <<< ExampleClass.example_static_method
DEBUG:__main__:  <<< ExampleClass.__init__

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

debug_this-1.0.0.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

debug_this-1.0.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page