httparty:如何记录请求?

问题描述 投票:0回答:4

如何记录使用 httparty 发送的请求?

HTTParty.post(
          @application_url,
          :headers => {
            "Accept"        => "application/json",
            "Content-Type"  => "application/json; charset=utf-8"
          },
          :body => {
            "ApplicationProfileId" => application.applicationProfileId
          }.to_json
        )
ruby logging httprequest httparty
4个回答
70
投票

在班级级别使用

debug_output

class Foo
  include HTTParty
  debug_output $stdout
end

或根据要求

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

6
投票

您可以使用内置记录器:

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

4
投票

使用类级别

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


0
投票

在 Rails 控制台中进行故障排除时,您可以使用以下命令打开所有 HTTParty 请求的调试日志记录:

HTTParty::Basement.debug_output $stdout
© www.soinside.com 2019 - 2024. All rights reserved.