Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
        )
like image 613
Eric Francis Avatar asked Mar 14 '14 20:03

Eric Francis


3 Answers

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)
like image 62
Brian Low Avatar answered Nov 06 '22 23:11

Brian Low


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
like image 5
Dende Avatar answered Nov 06 '22 22:11

Dende


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

like image 4
meagar Avatar answered Nov 07 '22 00:11

meagar