Encode before logging