Logger
Capture structured log output during test execution.

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:
Level | Method | Numeric Log Value | Console Flag | Description |
---|---|---|---|---|
Debug | test.logger.debug() | 10 | D | Detailed logs for troubleshooting |
Info | test.logger.info() | 20 | I | General messages |
Warning | test.logger.warning() | 30 | W | Signs of potential issues |
Error | test.logger.error() | 40 | E | Failures during test execution |
Critical | test.logger.critical() | 50 | C | Severe 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:
Flag | Output Level Printed |
---|---|
(none) | No logs |
-v | Info and above (≥ 20) |
-vv | Debug 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.

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

You can:
- Toggle between absolute and relative timestamps
- Filter by log level
- Sort logs chronologically
- Search for specific keywords
