Use a logger thread to prevent stdout races.