changed the way log files are named and implemented file close on exit