Logger API

class lily_unit_test.Logger(redirect_std=True, log_to_stdout=True)

Logger class. Handles all log messages and messages from stdout and stderr. The logger is part of the test suite and can be accessed by: TestSuite.log.

Parameters:
  • redirect_std – if True, stdout and stderr are redirected to the logger.

  • log_to_stdout – if True, log messages are written to the stdout (console).

All log messages are stored to an internal buffer (list of strings).
All log messages have the following format:

"<timestamp> | <type> | <message>"

<timestamp>: date and time of the message. Time is up to 1ms accurate.
<type>: Type of the message.
<message>: The message itself.

The message type can have one of the following values:

Type

Description

INFO
Informational message, usually for indicating generic test messages.
DEBUG
Debug message, usually for logging content of variables or more detailed test
messages.
ERROR
Error message, for reporting an error.
STDOUT
Standard output messages, messages that are written to standard output handler,
usually when using print().
STDERR
Standard error messages, messages that are written to standard error handler,
usually when an exception is raised.
debug(message)

Log a ‘debug’ type message.

Parameters:

message – the message to write to the logger.

empty_line()

Adds an empty line in the log messages.

error(message)

Log a ‘error’ type message.

Parameters:

message – the message to write to the logger.

get_log_messages()

Returns a reference to the log messages buffer.

Returns:

reference to the list of strings containing all log messages.

Note that it returns a reference, meaning any changes the logger makes to the list will
affect the reference.
To get a static copy of the log messages use: get_log_messages().copy().
This will return a new list with a copy of all the log messages at that moment.
handle_message(message_type, message_text)

Handles the message of a given type. This method is use by info(), debug(), error() and empty_line(). It is not encouraged to use this function, use with caution.

Parameters:
  • message_type – a string indicating the message type (see table above).

  • message_text – the message to write to the logger.

has_stderr_messages()
Returns:

True if a message from the STDERR handler was reported.

info(message)

Log a ‘info’ type message.

Parameters:

message – the message to write to the logger.

shutdown()

Shutdown the logger. This will restore the original stdout and stderr handlers.