'Logging hook called after a test finishs.'

@log.log_and_ignore_errors('post-test    sysinfo    error:')
def log_after_each_test(self, test):

    test_sysinfodir = self._get_sysinfodir(test.outputdir)
    reboot_dir = self._get_boot_subdir()
    assert os.path.exists(reboot_dir)
    symlink_dest = os.path.join(test_sysinfodir, 'reboot_current')
    symlink_src = utils.get_relative_path(reboot_dir, os.path.dirname(symlink_dest))
    try:
        os.symlink(symlink_src, symlink_dest)
    except Exception as e:
        raise Exception(('%s:    whilst    linking    %s    to    %s' % (e, symlink_src, symlink_dest)))
    for log in self.test_loggables:
        log.run(test_sysinfodir)
    self._log_messages(test_sysinfodir)
    keyval = self.log_test_keyvals(test_sysinfodir)
    test.write_test_keyval(keyval)
    if _LOG_INSTALLED_PACKAGES:
        old_packages = set(self._installed_packages)
        new_packages = set(self.sm.list_all())
        added_path = os.path.join(test_sysinfodir, 'added_packages')
        added_packages = ('\n'.join((new_packages - old_packages)) + '\n')
        utils.open_write_close(added_path, added_packages)
        removed_path = os.path.join(test_sysinfodir, 'removed_packages')
        removed_packages = ('\n'.join((old_packages - new_packages)) + '\n')
        utils.open_write_close(removed_path, removed_packages)
