Logging RestClient in a Rails app

前端 未结 5 1072
孤独总比滥情好
孤独总比滥情好 2021-01-18 08:47

I\'d like to debug the request my Rails app makes with RestClient. The RestClient docs say:

To enable logging you can

set RestClient.log w

相关标签:
5条回答
  • 2021-01-18 09:08

    from: https://gist.github.com/jeremy/1383337

    require 'restclient'
    
    # RestClient logs using << which isn't supported by the Rails logger,
    # so wrap it up with a little proxy object.
    RestClient.log =
      Object.new.tap do |proxy|
        def proxy.<<(message)
          Rails.logger.info message
        end
      end
    
    0 讨论(0)
  • 2021-01-18 09:08

    Create a file in config/initializers:
    RestClient.log = 'log/a_log_file.log'
    Or just put last in console

    https://github.com/adelevie/rest-client/commit/5a7ed325eaa091809141d3ef6e31087569614e9d

    0 讨论(0)
  • 2021-01-18 09:09

    This worked for me, running on RestClient 1.8 and Rails 4.2.1:

    ::RestClient.log = Rails.logger

    0 讨论(0)
  • 2021-01-18 09:18

    may be so: RestClient.log = Rails.logger

    0 讨论(0)
  • 2021-01-18 09:20

    You can use this gem:

    https://github.com/uswitch/rest-client-logger

    It works out of the box just by adding "gem 'rest-client-logger'" to your Gemfile.

    0 讨论(0)
提交回复
热议问题