Log first then send response
Check if headers are sent before sending the response