bwizzy
bwizzy

Reputation: 1599

HTTP Logging in rails?

Does anyone know of a plugin / gem that will log any HTTP requests your rails app may be making when responding to a request? For example if you are using HTTParty to hit an API, how can you see what outbound requests are coming out of your rails app?

Upvotes: 9

Views: 5701

Answers (5)

Michiel Kalkman
Michiel Kalkman

Reputation: 3054

You have to tell the outbound HTTP client to use a proxy.

For HTTParty it's fairly simple (from the docs),

class Twitter
    include HTTParty
    http_proxy 'http://myProxy', 1080

If you're looking for a proxy to set up, personally I like Paros proxy (Java so cross platform and does SSL).

Upvotes: 6

Thilo
Thilo

Reputation: 17735

Try my httplog gem, you can customize it to log requests, responses, headers etc.

Upvotes: 1

Bogdan Gusiev
Bogdan Gusiev

Reputation: 8305

Try also http_logger gem:

require 'http_logger'

Net::HTTP.logger = Logger.new(...) # defaults to Rails.logger if Rails is defined
Net::HTTP.colorize = true # Default: true

This will log all requests that goes through Net::HTTP library.

https://github.com/railsware/http_logger

Upvotes: 6

dira
dira

Reputation: 11

The only way I got this to work was to specify only the IP as the first parameter to the http_proxy call:

http_proxy '10.2.2.1', 8888

The example above, with the http:// prefix, did not work, I got a SocketError: getaddrinfo: nodename nor servname provided

Upvotes: 1

Erik Peterson
Erik Peterson

Reputation: 54

If you're doing development on your own machine, Charles Proxy is a good option.

In production, you'd probably be better off creating your own logger.debug() messages.

Upvotes: 1

Related Questions