Skip to content

Instantly share code, notes, and snippets.

@softwaregravy
Created March 7, 2011 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softwaregravy/858657 to your computer and use it in GitHub Desktop.
Save softwaregravy/858657 to your computer and use it in GitHub Desktop.
the code I use to log all requests and responses (watch out not to log html)
# inside Application controller
around_filter :global_request_logging
def global_request_logging
http_request_header_keys = request.headers.keys.select{|header_name| header_name.match("^HTTP.*")}
http_request_headers = request.headers.select{|header_name, header_value| http_request_header_keys.index(header_name)}
logger.info "Received #{request.method.inspect} to #{request.url.inspect} from #{request.remote_ip.inspect}. Processing with headers #{http_request_headers.inspect} and params #{params.inspect}"
begin
yield
ensure
logger.info "Responding with #{response.status.inspect} => #{response.body.inspect}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment