2014-03-06 15:18:45 -05:00
|
|
|
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
require File.join(dir, 'httparty')
|
|
|
|
require 'logger'
|
|
|
|
require 'pp'
|
|
|
|
|
|
|
|
my_logger = Logger.new "httparty.log"
|
|
|
|
|
|
|
|
my_logger.info "Logging can be used on the main HTTParty class. It logs redirects too."
|
|
|
|
HTTParty.get "http://google.com", logger: my_logger
|
|
|
|
|
2015-04-17 20:04:14 -04:00
|
|
|
my_logger.info '*' * 70
|
2014-03-06 15:18:45 -05:00
|
|
|
|
|
|
|
my_logger.info "It can be used also on a custom class."
|
|
|
|
|
|
|
|
class Google
|
|
|
|
include HTTParty
|
2015-04-18 06:30:52 -04:00
|
|
|
logger ::Logger.new "httparty.log"
|
2014-03-06 15:18:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Google.get "http://google.com"
|
|
|
|
|
2015-04-17 20:04:14 -04:00
|
|
|
my_logger.info '*' * 70
|
2014-03-06 15:18:45 -05:00
|
|
|
|
|
|
|
my_logger.info "The default formatter is :apache. The :curl formatter can also be used."
|
|
|
|
my_logger.info "You can tell wich method to call on the logger too. It is info by default."
|
|
|
|
HTTParty.get "http://google.com", logger: my_logger, log_level: :debug, log_format: :curl
|
|
|
|
|
2015-04-17 20:04:14 -04:00
|
|
|
my_logger.info '*' * 70
|
2014-03-06 15:18:45 -05:00
|
|
|
|
|
|
|
my_logger.info "These configs are also available on custom classes."
|
|
|
|
class Google
|
|
|
|
include HTTParty
|
2015-04-18 06:30:52 -04:00
|
|
|
logger ::Logger.new("httparty.log"), :debug, :curl
|
2014-03-06 15:18:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
Google.get "http://google.com"
|