Logging
Logging in the test framework uses the logging module from the Python standard library with the addition of custom logging levels. The following logging levels are available:
error
warning
skipped
note
action
detail
info
debug
The default directory for logging is the REST tree folder for the test. Logs are written to the <test_name>.py.log file.
Examples:
logging.detail("Current time is " + str(time.time()))
logging.detail(f"Test started at {time.time()}")
logging.error("Test suffered a critical failure")
Output:
Thu Jul 22 13:39:14 2021 DETAIL: The current time is 1626975554.542637
Thu Jul 22 13:39:14 2021 DETAIL: Test started at 1626975554.542928
Thu Jul 22 13:39:14 2021 ERROR: Test suffered a critical failure
There two additional options for loging.
Log a line with no timestamp.
Examples:
Note
The default resolution for the logger is seconds. This can be adjusted by including the proper overrides in /virtualun/python.conf.
More detail python.conf
Set resolution to milliseconds:
{"logging": {"resolution": "ms"}}
Set resolution to microseconds:
{"logging": {"resolution": "us"}}
Note
There are additional options for formatting output to logs:
Log a timestamp with no message
logging.detail(f'The current time is {time}') logging.empty() logging.detail(f'Test started at {time}')
Output:
Thu Jul 22 13:39:14 2021 DETAIL: The current time is 1626975554.542637 Thu Jul 22 13:39:15 2021 Thu Jul 22 13:39:16 2021 DETAIL: Test started at 1626975554.542928
Log a timestamp and a message with no level.
logging.detail(f'The current time is {time}') logging.empty('Left aligned text with a timestamp') logging.detail(f'Test started at {time}')
Output:
Thu Jul 22 13:39:14 2021 DETAIL: The current time is 1626975554.542637 Thu Jul 22 13:39:13 2021 Left aligned text with no timestamp Thu Jul 22 13:39:16 2021 DETAIL: Test started at 1626975554.542928
Log a totally blank line
logging.detail(f'The current time is {time}') logging.blank() logging.detail(f'Test started at {time}')
Output:
Thu Jul 22 13:39:14 2021 DETAIL: The current time is 1626975554.542637 Thu Jul 22 13:39:14 2021 DETAIL: Test started at 1626975554.542928
Log a message with no timestamp
logging.detail(f'The current time is {time}') logging.blank('Left aligned text with no timestamp') logging.detail(f'Test started at {time}')
Output:
Thu Jul 22 13:39:14 2021 DETAIL: The current time is 1626975554.542637 Left aligned text with no timestamp Thu Jul 22 13:39:14 2021 DETAIL: Test started at 1626975554.542928