improved logging to files, update #2668