def last_n_lines(the_string, n_lines, truncation_message=None):
    """Returns the last n lines of the given string

    Args:
        the_string: str
        n_lines: int
        truncation_message: str, optional

    Returns a string containing the last n lines of the_string

    If truncation_message is provided, the returned string begins with
    the given message if and only if the string is greater than n lines
    to begin with.
    """

    lines = the_string.splitlines(True)
    if len(lines) <= n_lines:
        return_val = the_string
    else:
        lines_subset = lines[-n_lines:]
        str_truncated = ''.join(lines_subset)
        if truncation_message:
            str_truncated = truncation_message + '\n' + str_truncated
        return_val = str_truncated

    return return_val