Welcome to debug_this’s documentation

https://img.shields.io/pypi/v/debug-this https://img.shields.io/readthedocs/python-debug-this https://img.shields.io/github/license/jmlemetayer/python-debug-this https://img.shields.io/github/workflow/status/jmlemetayer/python-debug-this/python-debug-this/main https://results.pre-commit.ci/badge/github/jmlemetayer/python-debug-this/main.svg https://img.shields.io/codecov/c/gh/jmlemetayer/python-debug-this/main

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__

License

The debug_this module is released under the MIT License