Eric Francis
Eric Francis

Reputation: 24287

httparty: how to log request?

How do I log requests being sent with with httparty?

HTTParty.post(
          @application_url,
          :headers => {
            "Accept"        => "application/json",
            "Content-Type"  => "application/json; charset=utf-8"
          },
          :body => {
            "ApplicationProfileId" => application.applicationProfileId
          }.to_json
        )

Upvotes: 37

Views: 21060

Answers (4)

Thai
Thai

Reputation: 11354

When troubleshooting in Rails console, you can turn on debug logging for all HTTParty Requests with:

HTTParty::Basement.debug_output $stdout

Upvotes: 1

Dende
Dende

Reputation: 584

You ca use a built-in logger:

my_logger = Rails.logger || Logger.new # use what you like
my_logger.info "The default formatter is :apache. The :curl formatter can also be used."
my_logger.info "You can tell which method to call on the logger too. It is info by default."

HTTParty.get "http://google.com", logger: my_logger, log_level: :debug, log_format: :curl

Upvotes: 6

Brian Low
Brian Low

Reputation: 11811

Use debug_output at the class level:

class Foo
  include HTTParty
  debug_output $stdout
end

or per request

response = HTTParty.post(url, :body => body, :debug_output => $stdout)

Upvotes: 71

user229044
user229044

Reputation: 239290

Use the class-level debug_output method to set an output stream where debugging information gets sent.

Upvotes: 4

Related Questions