File: logging.rb

package info (click to toggle)
ruby-httparty 0.13.7-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 736 kB
  • sloc: ruby: 4,741; xml: 425; sh: 35; makefile: 11
file content (36 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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

my_logger.info '*' * 70

my_logger.info "It can be used also on a custom class."

class Google
  include HTTParty
  logger ::Logger.new "httparty.log"
end

Google.get "http://google.com"

my_logger.info '*' * 70

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

my_logger.info '*' * 70

my_logger.info "These configs are also available on custom classes."
class Google
  include HTTParty
  logger ::Logger.new("httparty.log"), :debug, :curl
end

Google.get "http://google.com"