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

我想调试我的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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...