httparty:如何记录请求?

时间:2014-03-14 20:09:16

标签: ruby logging httprequest httparty

如何记录与httparty一起发送的请求?

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

3 个答案:

答案 0 :(得分:44)

在班级使用debug_output

class Foo
  include HTTParty
  debug_output $stdout
end

或按要求

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

答案 1 :(得分:4)

使用类级debug_output方法设置发送调试信息的输出流。

答案 2 :(得分:2)

您可以使用内置的记录器:

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