Trim output before logging, to prevent issues with \r.