Skip to main content
When running load tests, it’s often essential to capture debug information to understand what’s happening during test execution. LoadForge provides a simple way to log debug information that appears in your test results.
Debug logs can help you identify issues with your test scripts, track request flows, and validate data handling during test execution.

Using Print Statements

The simplest way to log debug information in LoadForge is by using Python’s standard print() function in your Locustfile. These print statements are captured and displayed in the “Errors & Logs” section of your test results.

Basic Logging Example

This example logs the status code of each request to the home page, helping you verify that requests are succeeding.

Logging Request Details

You can log more detailed information about requests and responses:
This example logs the status code and product count from an API response, with additional warnings for empty results or invalid JSON.

Logging Conditional Information

You can use conditional logic to only log information when certain conditions are met:
This example logs initialization information, selectively logs slow requests, and logs all cart operations.

Advanced Logging Techniques

Logging with Context

You can create more structured logs by including context information:
This example creates a custom logging method that includes session context, making it easier to track the flow of individual virtual users.

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.
Debug Logs

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

  1. Be Selective: Log only important information to avoid overwhelming the logs
  2. Include Context: Add timestamps, user IDs, or request identifiers to correlate logs
  3. Format Consistently: Use a consistent format for logs to make them easier to scan
  4. Log Failures: Always log details when errors or unexpected conditions occur
  5. Use for Debugging: Remove or reduce logging in production tests to improve performance
Excessive logging can impact test performance. Use logging judiciously, especially in high-volume tests.

Next Steps

Debugging Scripts

Learn more about debugging LoadForge test scripts

Run Results

Understand how to interpret your test results