Using Print Statements
The simplest way to log debug information in LoadForge is by using Python’s standardprint() function in your Locustfile. These print statements are captured and displayed in the “Errors & Logs” section of your test results.
Basic Logging Example
Logging Request Details
You can log more detailed information about requests and responses:Logging Conditional Information
You can use conditional logic to only log information when certain conditions are met:Advanced Logging Techniques
Logging with Context
You can create more structured logs by including context information:Viewing Logs in Test Results
After your test run completes, all print statements are collected and displayed in the “Errors & Logs” section of your test results. This provides valuable insights into what happened during the test execution.
Errors & Logs Section
Logs are collected from all workers and aggregated in the final report. This means you can see debug information from all virtual users across all LoadForge workers.
Best Practices for Logging
- Be Selective: Log only important information to avoid overwhelming the logs
- Include Context: Add timestamps, 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
- Use for Debugging: Remove or reduce logging in production tests to improve performance
Next Steps
Debugging Scripts
Learn more about debugging LoadForge test scripts
Run Results
Understand how to interpret your test results