TLDR: LoadForge has introduced a new debug logging feature that allows users to add Python `print()` statements in Locustfiles, simplifying load test troubleshooting and validation by automatically collecting and displaying logs in test results. This enhancement aids in debugging, request validation, flow tracking, and performance insights, with best practices suggesting selective logging and context inclusion for maximum effectiveness.
We're excited to announce a powerful new feature for LoadForge users: comprehensive debug logging for test runs. This highly requested capability makes it easier than ever to troubleshoot, validate, and understand what's happening during your load tests.
What's New
With this update, you can now use simple Python print()
statements in your Locustfiles to log debug information that will be automatically collected and displayed in your test results. This provides valuable insights into the behavior of your test scripts and the application under test.
How It Works
Using the debug logging feature is straightforward:
- Add
print()
statements to your Locustfile wherever you need to log information - Run your test as usual
- View the collected logs in the "Errors & Logs" section of your test results
Here's a simple example:
from locust import HttpUser, task, between
<p>class QuickstartUser(HttpUser):
wait_time = between(1, 5)</p>
<pre><code>@task
def view_home(self):
r = self.client.get("/")
print(f"view_home: status={r.status_code}")
This will log the status code of each request to your home page, making it easy to verify that requests are succeeding.
Key Benefits
- Simplified Debugging: Quickly identify issues in your test scripts or application behavior
- Request Validation: Verify that API calls are returning expected data
- Flow Tracking: Monitor the sequence of operations performed by virtual users
- Performance Insights: Log response times or other metrics to identify bottlenecks
- Aggregated Results: Logs from all workers are collected and displayed in a single view
Use Cases
Tracking API Responses
Log detailed information about API responses to verify data integrity:
with self.client.get("/api/products", catch_response=True) as response:
try:
data = response.json()
print(f"Products API: status={response.status_code}, count={len(data['products'])}")
<pre><code> if len(data['products']) == 0:
print("WARNING: Products API returned empty list")
response.failure("Empty product list")
except json.JSONDecodeError:
print(f"ERROR: Invalid JSON response: {response.text[:100]}...")
response.failure("Invalid JSON")
Monitoring Performance
Selectively log information about slow requests:
r = self.client.get(f"/products?category={category_id}")
<h1>Only log slow responses</h1>
<p>if r.elapsed.total_seconds() > 1.0:
print(f"SLOW REQUEST: /products?category={category_id} took {r.elapsed.total_seconds():.2f}s")
Tracking User Flows
Create structured logs to track complex user journeys:
def log(self, message):
"""Custom logging with session context"""
print(f"[{self.session_id}] {message}")
<p>@task
def multi_step_process(self):
self.log("Starting multi-step process")
# ... perform steps ...
self.log("Process completed")
Best Practices
To get the most out of debug logging, we recommend:
- Be Selective: Log only important information to avoid overwhelming the logs
- Include Context: Add user IDs or request identifiers to correlate logs
- Format Consistently: Use a consistent format for logs to make them easier to scan
- Log Failures: Always log details when errors or unexpected conditions occur
Documentation
For more detailed information on using debug logging in your LoadForge tests, check out our new documentation page.
What's Next
We're continuously working to improve LoadForge based on your feedback. Debug logging is just one of many enhancements we have planned to make your load testing experience more productive and insightful.
Have questions or feedback about this new feature? We'd love to hear from you! Reach out to us at [email protected] or use the live chat in the LoadForge dashboard.
Happy testing!