generic method compareandlog