Logger

Capture structured log output during test execution.

Screenshot of Tofupilot illustrating the station feature.

Overview

Logging is crucial for debugging and tracking test execution. OpenHTF provides a built-in logger that captures detailed outputs, custom messages, and error traces, which are saved to test records through output callbacks. All logs are saved to the test record via output callbacks, and they are visible directly on each Run page in TofuPilot. This makes it easy to trace issues and understand what happened at each step of the test.

Integration

You can log from any phase or plug using OpenHTF logger. All log levels are captured and processed by TofuPilot.

import openhtf as htf
from tofupilot.openhtf import TofuPilot


@htf.measures(htf.Measurement("boolean_measure").equals(True))
def phase_with_info_logger(test):
    test.measurements.boolean_measure = True
    # You can log info, warning, error, and critical. By default, debug.
    test.logger.info("Logging an information")


def main():
    test = htf.Test(
        phase_with_info_logger,
        procedure_id="FVT1",
        part_number="PCB01",
    )

    with TofuPilot(test):
        test.execute(lambda: "PCB1A001")


if __name__ == "__main__":
    main()

Logging levels

You can use five logging levels depending on the severity of the event:

LevelMethodNumeric Log ValueConsole FlagDescription
Debugtest.logger.debug()10DDetailed logs for troubleshooting
Infotest.logger.info()20IGeneral messages
Warningtest.logger.warning()30WSigns of potential issues
Errortest.logger.error()40EFailures during test execution
Criticaltest.logger.critical()50CSevere failures or crashes

By default, OpenHTF logs everything at the debug level.

Logs in output callbacks

When output callbacks are enabled, logs are included in the report file. Each log entry includes its numeric level, source file, line number, timestamp, and message.

test_results.json

"log_records": [
    {
      "level": 30,
      "logger_name": "openhtf.test_record..phase.phase_test",
      "source": "main.py",
      "lineno": 11,
      "timestamp_millis": 1729163738931,
      "message": "Warning in test phase: Potential issue."
    },
  ...
]

Console output

You can control how logs are displayed in the terminal with the -v flag. The console flag will prefix each log line with the log level (e.g., I, W, E) to indicate its severity:

FlagOutput Level Printed
(none)No logs
-vInfo and above (≥ 20)
-vvDebug and above (≥ 10)
python main.py -v

Terminal

I 15:11:48 test_descriptor - Executing test:
I 15:11:48  - Test phase started.
W 15:11:48  - Warning in test phase: Potential issue.
E 15:11:48  - Test phase error: Error occurred in test phase.
I 15:11:48  - Teardown phase

For more advanced usage and customization, refer to the OpenHTF logging documentation.

In-app view

You can explore all log events directly from the TofuPilot UI, on each Run page.

Screenshot of Tofupilot illustrating the station feature.

Each log entry can be expanded to view additional metadata such as source filename, line number, and timestamp.

Screenshot of Tofupilot illustrating the station feature.

You can:

  • Toggle between absolute and relative timestamps
  • Filter by log level
  • Sort logs chronologically
  • Search for specific keywords
Screenshot of Tofupilot illustrating the station feature.

Was this page helpful?