Trace Book
Trace Book is a Python package designed for comprehensive code bookkeeping. It provides tools to log function calls, parameters, return values, and execution times. Additionally, it supports decorators for easy integration, automatic error tracking, and remote log transmission, all with customizable log levels and output configurations.
Features
- Function Logging: Track function calls, parameters, return values, and execution times.
- Automatic Error Tracking: Log exceptions and stack traces automatically.
- Decorators: Simplify logging with decorators that track function parameters and results.
- Remote Log Transmission: Securely send logs to a remote server.
- Customizable Log Levels: Control log verbosity with DEBUG, INFO, WARNING, and ERROR levels.
- Configurable Output: Choose between logging to console, files, or transmitting logs to a remote server.
- Web UI: Visualize logs and system performance metrics through a customizable dashboard.
Installation
You can install Trace Book using pip:
pip install tracebook
Or by cloning the repository and installing it manually:
git clone https://github.com/yourusername/tracebook.git
cd tracebook
pip install .
Usage
Basic Logging
from tracebook import Logger
from tracebook.config import Config, LogLevel
logger = Logger(config=Config(log_level=LogLevel.INFO, output="both", file_path="app.log"))
@logger.trace()
def add(a, b):
return a + b
result = add(3, 5)
print(f"Result: {result}")
Logging with Resource Tracking
@logger.trace(log_resources=True)
def compute_factorial(n):
if n == 0:
return 1
return n * compute_factorial(n - 1)
compute_factorial(5)
Using Different Log Levels
logger.debug("Debugging information")
logger.info("General information")
logger.warning("Warning: resource running low")
logger.error("Error occurred: unable to connect")
logger.critical("Critical: system shutdown imminent")
Exception Handling
@logger.trace()
def divide(a, b):
return a / b
try:
divide(10, 0)
except ZeroDivisionError:
logger.error("Attempted division by zero")
Remote Logging Configuration
from tracebook.config import RemoteConfig
remote_logger = Logger(
config=Config(
log_level=LogLevel.INFO,
output="file",
remote_config=RemoteConfig(
url="https://logs.example.com",
headers={"Authorization": "Bearer your-token"}
)
)
)
@remote_logger.trace()
def important_function():
# Function logic here
pass
Internally teacebook will do a POST call to your server with the file as the payload.
curl -X POST "http://example.com/upload" \
-H "Content-Type: multipart/form-data" \
-H "Authorization: Bearer your_token_here" \
-F "file=@/path/to/your/logfile.log"
Web UI Configuration
from tracebook.config import WebUIConfig
web_logger = Logger(
config=Config(
log_level=LogLevel.INFO,
output="both",
web_config=WebUIConfig(
title="My TraceBook Dashboard",
foreground_color="#123456",
background_color="#F0F0F0",
show_star_on_github=True,
indent_logs=True,
is_active=True,
port=2234,
refresh_interval=2000,
max_data_points=200,
)
)
)
@web_logger.trace()
def monitor_system():
# Function logic here
pass
Configuring Log Levels and Output
Control the verbosity of logs by setting the log level and choosing the output:
from tracebook import Logger
from tracebook.config import Config, LogLevel
logger = Logger(
config=Config(
log_level=LogLevel.DEBUG,
output="both",
file_path="logs.txt"
)
)
@logger.trace(log_resources=True)
def my_function(param1, param2):
return param1 + param2
my_function(1, 2)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for tracebook 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tracebook-0.1.10.tar.gz | 15.7 kB | Without provenance | Details for tracebook-0.1.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tracebook-0.1.10-py3-none-any.whl | Python 3 | none | any | Details for tracebook-0.1.10-py3-none-any.whl |
Total release size: 30.1 kB
Release files / tracebook-0.1.10.tar.gz
| Download URL | tracebook-0.1.10.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96668529359282d3d91f96aab25e29cc43305a3d1ec4b26249ec1d5e90bd73aa
|
|
BLAKE2b-256 checksum How to use checksums |
e1f139acbbfe5afb93633c5456b69cb98528d0834fd62eadef7570146539ee48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / tracebook-0.1.10-py3-none-any.whl
| Download URL | tracebook-0.1.10-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5e4974938822d214d4639b1caf72b40d65ba798ee27fc28183f795cc2da20695
|
|
BLAKE2b-256 checksum How to use checksums |
f2c2ba2d83685a2d2ee178973cfa8e233c9eb75a620ba230fe60bfa26e4cbd1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for tracebook 0.1.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.