Log content escapeing

Also fixed misplacement of close(IN) in my previous patch.