fixed log file issues : opening and flushing