flush logfile before file close