No project description provided
Project description
Tracelogger
Tag your functions with the @tracelogger
decorator to be logged line-by-line.
Optionally provide a function as the printer
argument that takes the local variable dictionary and returns a string. This allows the customisation of which variables and how you want to print at each line. See the example with the provided names_printer
function that only prints a selected set of variables.
The second width
parameter determines the maximum character number for each line of code defaulting to 80
.
from tracelogger import tracelogger, names_printer
@tracelogger(width=30)
def second_test_function(x):
y = x**2
return y
@tracelogger(printer=lambda locals_: names_printer(locals_=locals_, names=['k', 'b']), width=30)
def first_test_function(a, b):
c = a + b
for k in range(5):
if k % 2 == 0:
b += k
else:
c += k
second_test_function(c)
return a, b, c
a, b, c = first_test_function(a=10, b=20)
This will print the following:
Entering function: first_test_function
c = a + b locals: b=20
for k in range(5): locals: b=20
if k % 2 == 0: locals: b=20, k=0
b += k locals: b=20, k=0
for k in range(5): locals: b=20, k=0
if k % 2 == 0: locals: b=20, k=1
c += k locals: b=20, k=1
second_test_function(c) locals: b=20, k=1
Entering function: second_test_function
y = x**2 locals: x=31
return y locals: x=31, y=961
return y locals: x=31, y=961
Returning from: second_test_function() to: first_test_function()
for k in range(5): locals: b=20, k=1
if k % 2 == 0: locals: b=20, k=2
b += k locals: b=20, k=2
for k in range(5): locals: b=22, k=2
if k % 2 == 0: locals: b=22, k=3
c += k locals: b=22, k=3
second_test_function(c) locals: b=22, k=3
Entering function: second_test_function
y = x**2 locals: x=34
return y locals: x=34, y=1156
return y locals: x=34, y=1156
Returning from: second_test_function() to: first_test_function()
for k in range(5): locals: b=22, k=3
if k % 2 == 0: locals: b=22, k=4
b += k locals: b=22, k=4
for k in range(5): locals: b=26, k=4
return a, b, c locals: b=26, k=4
return a, b, c locals: b=26, k=4
Returning from: first_test_function() to: None
Join the Code Quality for Data Science (CQ4DS) Discord channel for feedback.
I used the following StackOverflow threads as sources, many thanks to their authors:
https://stackoverflow.com/questions/22362940/inspect-code-of-next-line-in-python
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
Built Distribution
File details
Details for the file tracelogger-0.1.2.tar.gz
.
File metadata
- Download URL: tracelogger-0.1.2.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.6 Linux/6.2.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b97129783786031d9eb7d175b27cfbe4d6064312683ed2422a2b2f4ca0c45a00 |
|
MD5 | f635f577a878e5f8e05d57d1ad2db156 |
|
BLAKE2b-256 | dd0536700eabfbe8d0d13db9b7a2af10d5ca4e687a5bcdde7da6b506d1da4dde |
File details
Details for the file tracelogger-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: tracelogger-0.1.2-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.11.6 Linux/6.2.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb14e8dec3bbde6383bc270e76b98d5c9572403aadb52b6fd390772e4cce8bd |
|
MD5 | f6187f14c4979d4ad0aa9791cc090e14 |
|
BLAKE2b-256 | 8799af0ec266d18d8ef5a97efe4eb895d9c0eac1b306af6bf0a70d7f5beefab0 |