加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails应用程序中记录RestClient

发布时间:2020-12-16 21:38:01 所属栏目:百科 来源:网络整理
导读:我想调试我的Rails应用程序使用 RestClient创建的请求.RestClient文档说: To enable logging you can set RestClient.log with a ruby Logger or set an environment variable to avoid modifying the code (in this case you can use a file name,“stdout
我想调试我的Rails应用程序使用 RestClient创建的请求.RestClient文档说:

To enable logging you can

set RestClient.log with a ruby Logger
or set an environment variable to avoid modifying the code (in this case you can use a file name,“stdout” or “stderr”):

$RESTCLIENT_LOG=stdout path/to/my/program
Either produces logs like this:

RestClient.get “07001”

=> 200 OK | text/html 250 bytes

RestClient.put “07001”,“payload”

=> 401 Unauthorized | application/xml 340 bytes

Note that these logs are valid Ruby,so you can paste them into the restclient shell or a >script to replay your sequence of rest calls.

如何将这些日志包含在我的Rails应用程序日志文件夹中?

解决方法

来自: 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读