fix a bug to make sure to stop the logging  before you exit