<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_history_log(history_log, clear=False, description=None, test_log=None):
 """ Update the history log file with item. If clear flag is provided the log file is deleted. """

    if not test_log and not clear:
        raise IpaUtilsException(
            'A test log or clear flag must be provided.'
        )

    if clear:
        with ignored(OSError):
            os.remove(history_log)

    else:
        history_dir = os.path.dirname(history_log)
        if not os.path.isdir(history_dir):
            try:
                os.makedirs(history_dir)
            except OSError as error:
                raise IpaUtilsException(
                    'Unable to create directory: %s' % error
                )

        with open(history_log, 'a+') as f:
            # Using append mode creates file if it does not exist
            if description:
                description = '"%s"' % description

            out = '{} {}'.format(
                test_log,
                description or ''
            )
            f.write(out.strip() + '\n')