Tuesday, November 5, 2013

Ruby: Adding logger with Mechanize


Share at Facebook

Ruby mechanize is having a built-in logging option that you can use very easily. It will help you debugging the HTTP calls along with the headers that were handled by the mechanize. Here is the example:


require 'rubygems'
require 'mechanize'
require 'logger'

agent = Mechanize.new { |a|
    a.user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'
    a.follow_meta_refresh = true
}
agent.log = Logger.new "mechanize.log"



you'll find all your info and debugging output inside the mechanize.log file.





No comments: