format an error into string or json for log