Skip to main content

Python debug and tracer library

Project description

traceme

Is a structlog helper library that helps you to debug and trace your code. It aims to replace print debugging with a more powerful and permanent solution.

Installation

pip install traceme

Usage

import math
from collections.abc import Callable

import structlog

import traceme


logger = structlog.get_logger()

@traceme.info(exit=True)
def add(a: int, b: int, cont: Callable[[int], None]) -> None:
    cont(a + b)


@traceme.info(exit=True)
def square(a: int, cont: Callable[[int], None]) -> None:
    cont(a * a)


@traceme.info(exit=True)
def sqrt(a: int, cont: Callable[[int], None]) -> None:
    cont(int(math.sqrt(a)))


@traceme.info(exit=True)
def pythagoras(a: int, b: int, cont: Callable[[int], None]) -> None:
    square(
        a,
        lambda a2: square(
            b,
            lambda b2: add(
                a2,
                b2,
                lambda a2b2: sqrt(
                    a2b2,
                    cont,
                ),
            ),
        ),
    )


if __name__ == "__main__":
    traceme.configure()

    pythagoras(3, 4, lambda result: logger.info("The result is", result=result))

This will output:

 poetry run python tests/test_pythagoras.py
2024-02-10T15:52:19.284431Z [info     ]   pythagoras args=(3, 4, <function <lambda> at 0x1040c2840>) kwargs={} module=test_pythagoras
2024-02-10T15:52:19.313361Z [info     ]      square args=(3, <function pythagoras.<locals>.<lambda> at 0x1040c2ac0>) kwargs={} module=test_pythagoras
2024-02-10T15:52:19.313621Z [info     ]         square args=(4, <function pythagoras.<locals>.<lambda>.<locals>.<lambda> at 0x1040c2c00>) kwargs={} module=test_pythagoras
2024-02-10T15:52:19.314165Z [debug    ]            add args=(9, 16, <function pythagoras.<locals>.<lambda>.<locals>.<lambda>.<locals>.<lambda> at 0x1040c2ca0>) kwargs={} module=test_pythagoras
2024-02-10T15:52:19.314407Z [info     ]               sqrt args=(25, <function <lambda> at 0x1040c2840>) kwargs={} module=test_pythagoras
2024-02-10T15:52:19.314616Z [debug    ]                 The result is module=test_pythagoras result=5
2024-02-10T15:52:19.314806Z [info     ]               sqrt elapsed=399 us module=test_pythagoras
2024-02-10T15:52:19.315301Z [info     ]         square elapsed=1.68 ms module=test_pythagoras
2024-02-10T15:52:19.315493Z [info     ]      square elapsed=2.15 ms module=test_pythagoras
2024-02-10T15:52:19.315676Z [info     ]   pythagoras elapsed=31.27 ms module=test_pythagoras

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

traceme-0.5.0.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

traceme-0.5.0-py3-none-any.whl (5.5 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