2011-05-10 42 views
0

我記得在GitHub上看到了這個描述的寶石,但現在我找不到它了。用於監視其他寶石HTTP調用的Ruby寶石?

這個想法是,它會讓你看到其他寶石用來做他們魔法的實際API調用/服務端點。

我不記得它是專門針對HTTP還是什麼。

+0

發現:https://github.com/railsware/http_logger – dleavitt 2011-06-02 02:22:14

回答

3

我不知道那個gem,但是你可以通過打開ruby的Net :: HTTP類,在實際的HTTP調用之前別名現有的方法和添加一些日誌記錄調用來輕鬆地重新創建該功能。

例如,這裏是你如何可以打印調用獲得到stdout:

 
require 'rubygems' 
require 'net/http' 

class Net::HTTP 
    # Note that you have to be in the singleton class to alias a class method 
    class << self 
    alias_method :orig_get, :get 

    def get(uri_or_host, path=nil, port=nil) 
     # here's where you log theactivity, before calling the original method 
     puts "GET: #{uri_or_host}#{':' + port if port}#{path}" 
     orig_get(uri_or_host, path, port) 
    end 
    end 
end 
+0

更加美好!謝謝! – dleavitt 2011-05-10 22:44:44