Skip to main content

Decorator functions to trace invocation of functions and class methods.

Project description

ftracer Package

ftracer - decorator functions to trace invocation of functions and class methods

DESCRIPTION

A Python module for tracing function and method invocations with detailed, customizable logging. The ftracer module provides tools for decorating individual functions, all functions in a module, and all methods in a class to log their invocation, arguments, and return values. This is particularly useful for debugging and understanding the flow of execution in your code.

ftracer allows developers to:

  • Decorate individual functions with the @trace decorator to log their calls.
  • Decorate entire classes with the @trace_methods decorator to trace all method calls within a class.
  • Automatically attach decorators to all functions or classes in a module using trace_all_functions and trace_all_classes.
  • Customize the tracing behavior, such as pretty-printing arguments and limiting list representations.

Key features:

  • Customizable pretty-printer for function arguments and return values.
  • Ability to apply tracing globally to all functions or classes in a module.
  • Optional debug mode for additional trace logs.

EXAMPLE

Tracing Individual Functions

from ftracer import trace

@trace
def add(a, b):
    return a + b

result = add(5, 3)
** add(a=5, b=3)

Tracing All Methods in a Class

from ftracer import trace_methods

@trace_methods
class Calculator:
    def multiply(self, x, y):
        return x * y

calc = Calculator()
calc.multiply(4, 7)
** multiply(self=<Calculator>, x=4, y=7)

Applying Traces Globally in a Module

from ftracer import trace_all_functions

trace_all_functions()

def greet(name):
    return f"Hello, {name}!"

greet("Alice")
** greet(name='Alice')

INSTALLATION

pip3 install ftracer

AVAILABILITY

The latest version of ftracer module is available at PyPI (https://pypi.org/project/ftracer/) .

SEE ALSO

AUTHOR

Hiroyuki Ohsaki <ohsaki[atmark]lsnl.jp>

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

ftracer-1.2.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

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

ftracer-1.2-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file ftracer-1.2.tar.gz.

File metadata

  • Download URL: ftracer-1.2.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for ftracer-1.2.tar.gz
Algorithm Hash digest
SHA256 c075fa71a556bd0fa37d8c2e993fd06dcc4b3d3495fe2f4c56585296f380cac1
MD5 edf4218d713d7b27a52af38f3b93afdb
BLAKE2b-256 ac28a7b582de7e40520c997a90cf9b4a9a93766f0be425f8967847317025272b

See more details on using hashes here.

File details

Details for the file ftracer-1.2-py3-none-any.whl.

File metadata

  • Download URL: ftracer-1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.2

File hashes

Hashes for ftracer-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eac8ae2ed5e3c70a12a839ff5df5f8ecada90c1338db93e0ad95d1d7a30d0d96
MD5 23caa7e896b6e0b0777f6de4cb2d197a
BLAKE2b-256 06016d038979624f9c459431f2cbefec61cb7a076b2b8d9bf178351502ccf452

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