A lightweight tracing library for python
Project description
easytrace
A lightweight tracing library for python3, it provides an alternative to attaching a heavy debugger and manually printing out arguments when you enter functions.
Installation
Install from the PyPi project using pip:
pip install easytrace
There are no dependencies required other than Python3!
Usage
Basic
First import the trace decorator at the top of your file, setting the logging level as desired. Note, easytrace uses the DEBUG log level by default. Although this can be changed.
A full example can be found in tests/test.py
from easytrace.trace import trace
import logging
logging.basicConfig(level=logging.DEBUG)
Simply add the @trace decorator above and function/method you would like to trace.
@trace
def add_integers(a: int, b: int) -> int:
return a + b
Invoking this with add_integers(2, 3) will produce the following trace:
DEBUG:easytrace:call add_integers(a : str = 2, b : str = 3)
DEBUG:easytrace:return add_integers -> int = 5
Parameters
The decorator has the following parameters:
enter - Custom string to display when entering function, overrides default
exit - Custom string to display when leaving function, overrides default
arg_value - Should display argument values in trace
return_value - Should display return value in trace
log_level - Log level to use for this trace, overrides default
stream - Additional stream to write to for this trace, overrides default
An example of not logging the return value at the INFO logging level is as follows:
@trace(return_value=False, log_level=logging.INFO)
def function(s: str) -> str:
...
Default Options
To set default options, do the following:
from easytrace.trace import TraceConfig
TraceConfig.set_stream(open("log.log", "w")) # will set the default logging stream (excluding stdout) to the file "log.log"
TraceConfig.set_logging_level(logging.INFO) # will set the default logging level to INFO
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 easytrace-0.0.3.tar.gz.
File metadata
- Download URL: easytrace-0.0.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10955b2497b225ab539943a2fea86f5774c489ff7b08a8ff0d7f1df0c32dd40d
|
|
| MD5 |
ec23e9107b6d0a61224143b470e90303
|
|
| BLAKE2b-256 |
162b6030a2ce61e79f148cbf145b3a4cbefaa3304b88c917bc6a7371fe56eb2d
|
File details
Details for the file easytrace-0.0.3-py3-none-any.whl.
File metadata
- Download URL: easytrace-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e77fd9d2202925a94243a48506b101ee8d706a2a613a3719eab20841b5689ca5
|
|
| MD5 |
78a2f3c0766cb68a7151272445ffd1e9
|
|
| BLAKE2b-256 |
4429a74eea6ca5d88fa0a9bb55e08fa09d8cc1e33bbdc45fa2924db318c81619
|