A small package for tracing function calls
Project description
Call Traces
A small package for tracing function calls
Installing ⏬
pip install calltraces
Usage 📝
Python code:
from calltraces.linetrace import traceInfo
from calltraces.functiontrace import functiontrace
# ...
@functiontrace # Add a function decorator
def myFunction():
traceInfo("some log message...")
# ...
# Whenever the function is called:
myFunction()
This will produce the output:
[INFO:01] 2022-06-26 18:00:32,234 __main__.myFunction Starting Function
[INFO:02] 2022-06-26 18:00:32,235 some log message...
[INFO:01] 2022-06-26 18:00:32,235 __main__.myFunction Finished Function
Advanced Usage 🪆
Python code:
from calltraces.linetrace import traceInfo
from calltraces.functiontrace import functiontrace
# ...
@functiontrace
def myFunction1():
traceInfo("some log message...")
@functiontrace
def myFunction2():
myFunction1()
@functiontrace
def myFunction3():
# Calling a function twice
myFunction2()
myFunction2()
# ...
# Whenever the function is called:
myFunction3()
This will produce the output:
[INFO:01] 2022-06-26 18:06:38,625 __main__.myFunction3 Starting Function
[INFO:02] 2022-06-26 18:06:38,626 __main__.myFunction2 Starting Function
[INFO:03] 2022-06-26 18:06:38,634 __main__.myFunction1 Starting Function
[INFO:04] 2022-06-26 18:06:38,634 some log message...
[INFO:03] 2022-06-26 18:06:38,634 __main__.myFunction1 Finished Function
[INFO:02] 2022-06-26 18:06:38,634 __main__.myFunction2 Finished Function
[INFO:02] 2022-06-26 18:06:38,634 __main__.myFunction2 Starting Function
[INFO:03] 2022-06-26 18:06:38,635 __main__.myFunction1 Starting Function
[INFO:04] 2022-06-26 18:06:38,635 some log message...
[INFO:03] 2022-06-26 18:06:38,635 __main__.myFunction1 Finished Function
[INFO:02] 2022-06-26 18:06:38,635 __main__.myFunction2 Finished Function
[INFO:01] 2022-06-26 18:06:38,635 __main__.myFunction3 Finished Function
Usage with classes 📦
Adding the python decorator on a class will automatically add trace wrappers to public functions.
⚠️ Private functions will stay unaffected.
Python code:
from calltraces.linetrace import traceInfo
from calltraces.classtrace import classtrace
# ...
@classtrace # Add a class decorator
class MyObject:
def __init__(self, input) -> None:
self._x = input
def _privateFunction(self):
self._x = self._x * 2
def __superPrivateFunction(self):
self._x = self._x * 3
def publicBaseFunction(self):
self._privateFunction()
self.__superPrivateFunction()
traceInfo("some log message...")
def publicWrapperFunction(self) -> None:
return self.publicBaseFunction()
# ...
# Whenever the object functions are called
myObj = MyObject(input=12345)
myObj.publicWrapperFunction()
This will produce the output:
[INFO:01] 2022-06-26 18:17:15,456 __main__.MyObject.publicWrapperFunction Starting Function
[INFO:02] 2022-06-26 18:17:15,456 __main__.MyObject.publicBaseFunction Starting Function
[INFO:03] 2022-06-26 18:17:15,456 some log message...
[INFO:02] 2022-06-26 18:17:15,456 __main__.MyObject.publicBaseFunction Finished Function
[INFO:01] 2022-06-26 18:17:15,456 __main__.MyObject.publicWrapperFunction Finished Function
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file calltraces-2022.7.5.2.tar.gz.
File metadata
- Download URL: calltraces-2022.7.5.2.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88a8ec04407293ed1fe126fc9685c241e450c85bf82b2a09d425c81486b8eb21
|
|
| MD5 |
61c5575e9fa9418e0037247c22c7f133
|
|
| BLAKE2b-256 |
cbc5c37039b0241f794f0dd5d1359342d11dc23e058d22d12dc5d6e6a83ca942
|
File details
Details for the file calltraces-2022.7.5.2-py3-none-any.whl.
File metadata
- Download URL: calltraces-2022.7.5.2-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd2247d6b913ef9c188e53755206aa2845d05dca4c713ee4e2f9d2339292d58c
|
|
| MD5 |
bea7ee7785da2ba0b7e03d0ede08a257
|
|
| BLAKE2b-256 |
0813fae365c390764cf4cbd771f74442e4d68cfbcb910338f0d9c3143360616b
|