Skip to main content

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
Screenshot 2024-05-25 at 12 02 27

Switching traceme to Environment.PRODUCTION will remove all the indentation.

traceme.configure(Environment.PRODUCTION)
{"event": "pythagoras", "timestamp": "2024-05-25T09:49:09.802510Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.802929Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.802991Z", "level": "info"}
{"event": "add", "timestamp": "2024-05-25T09:49:09.803050Z", "level": "debug"}
{"event": "sqrt", "timestamp": "2024-05-25T09:49:09.803101Z", "level": "info"}
{"result": 5, "event": "The result is", "timestamp": "2024-05-25T09:49:09.803147Z", "level": "debug"}
{"event": "sqrt", "timestamp": "2024-05-25T09:49:09.803200Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.803248Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.803291Z", "level": "info"}
{"event": "pythagoras", "timestamp": "2024-05-25T09:49:09.803335Z", "level": "info"}

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.6.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

traceme-0.6.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file traceme-0.6.0.tar.gz.

File metadata

  • Download URL: traceme-0.6.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1021-azure

File hashes

Hashes for traceme-0.6.0.tar.gz
Algorithm Hash digest
SHA256 d3a9f4155d6c4100748d603b39f55891db1cb5bf857c32d7adeca8547600b3c8
MD5 c77c95abf6bea967b3ddd91364dadc3e
BLAKE2b-256 ed79816ff26828bbdbfc71238327032d8ae78f29226c2e1be65ab09874451c62

See more details on using hashes here.

File details

Details for the file traceme-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: traceme-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1021-azure

File hashes

Hashes for traceme-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fb8ee6a24e037ccd7f4f41ac62c3d3e01bee0e47f7827306d2d21105fc885a1
MD5 bd5af2c0880eae8fb9829f8c3241052e
BLAKE2b-256 fd523cea560f9b5d6b6ec9f14f20fd2d76c94053678ef80f7e94f0acf77634ff

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page