Make logging more robust