Treebeard
Treebeard is a Python library for efficient log forwarding with support for trace contexts and batched logging.
Installation
pip install treebeardhq
Quick Start
from treebeardhq import Treebeard, Log
Treebeard.init(
api_key="your-api-key",
endpoint="https://your-logging-endpoint.com/logs"
)
trace_id = Log.start("image-processing")
try:
Log.info("Starting image processing", image_format="PNG")
Log.debug("Image validation", data={"dimensions": [1920, 1080], "color_space": "RGB"})
Log.info("Image processed successfully", output_size_kb=256)
except Exception as e:
Log.error("Processing failed", error=str(e))
finally:
Log.end()
Logging Levels
Treebeard supports multiple logging levels:
Log.debug("Debug information")
Log.info("General information")
Log.warning("Warning message")
Log.error("Error message")
Adding Context Data
You can add metadata to your logs in two ways:
)
Log.info("User action",
user_id="123",
action="login",
ip="192.168.1.1"
)
Trace Contexts
Trace contexts help you group related logs together:
trace_id = Log.start("payment-processing")
Log.info("Processing payment")
Log.debug("Validating card details")
Log.end()
Configuration Options
When initializing Treebeard, you can configure several options:
Treebeard.init(
api_key="your-api-key",
endpoint="https://your-logging-endpoint.com/logs",
debug_mode=True,
batch_size=100,
batch_age=5.0,
threading_mode="thread"
)
Thread Safety
Treebeard is thread-safe and supports different threading modes:
- Standard Python threading (default)
- Eventlet
- Gevent
License
MIT License - see LICENSE file for details.