httplog 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ Log outgoing HTTP requests made from your application.
5
5
  == Installation
6
6
 
7
7
  gem install httplog
8
-
8
+
9
9
  == Usage
10
10
 
11
11
  require 'httplog'
@@ -24,12 +24,18 @@ You can override the following default options:
24
24
  HttpLog.options[:log_status] = true
25
25
  HttpLog.options[:log_response] = true
26
26
  HttpLog.options[:log_benchmark] = true
27
+ HttpLog.options[:compact_log] = false # setting this to true will make all "log_*" options redundant
27
28
 
28
29
  So if you want to use this in a Rails app:
29
30
 
30
31
  # file: config/initializers/httplog.rb
31
-
32
+
32
33
  HttpLog.options[:logger] = Rails.logger
33
34
 
35
+ == Development
34
36
 
37
+ To run the tests, a web server must be listening on localhost port 3000. Then simply
38
+ run `bundle exec rake`. The tests will make GET and POST requests to `http://localhost:3000/foo` by
39
+ default.
35
40
 
41
+ TODO: Make tests self-contained.
@@ -2,7 +2,7 @@ require "net/http"
2
2
  require "logger"
3
3
 
4
4
  module HttpLog
5
-
5
+
6
6
  def self.options
7
7
  @@options ||= {
8
8
  :logger => Logger.new($stdout),
@@ -12,14 +12,15 @@ module HttpLog
12
12
  :log_data => true,
13
13
  :log_status => true,
14
14
  :log_response => true,
15
- :log_benchmark => true
15
+ :log_benchmark => true,
16
+ :log_compact => false
16
17
  }
17
18
  end
18
-
19
+
19
20
  def self.log(msg)
20
21
  @@options[:logger].add(@@options[:severity]) { msg }
21
22
  end
22
-
23
+
23
24
  end
24
25
 
25
26
  module Net
@@ -30,38 +31,42 @@ module Net
30
31
 
31
32
  def request(req, body = nil, &block)
32
33
 
33
- if started?
34
+ if started? && !HttpLog.options[:compact_log]
34
35
  if HttpLog.options[:log_request]
35
36
  HttpLog::log("[httplog] Sending: #{req.method} http://#{@address}:#{@port}#{req.path}")
36
37
  end
37
-
38
- if req.method == "POST" && HttpLog.options[:log_data]
39
- # a bit convoluted becase post_form uses form_data= to assign the data, so
38
+
39
+ if req.method == "POST" && HttpLog.options[:log_data]
40
+ # a bit convoluted becase post_form uses form_data= to assign the data, so
40
41
  # in that case req.body will be empty
41
42
  data = req.body.nil? || req.body.size == 0 ? body : req.body
42
- HttpLog::log("[httplog] Data: #{data}")
43
+ HttpLog::log("[httplog] Data: #{data}")
43
44
  end
44
45
  end
45
-
46
+
46
47
  r0 = Time.now
47
48
  response = orig_request(req, body, &block)
48
-
49
+
49
50
  benchmark = Time.now - r0
50
51
  if started?
51
- HttpLog::log("[httplog] Benchmark: #{benchmark}") if HttpLog.options[:log_benchmark]
52
- HttpLog::log("[httplog] Status: #{response.code}") if HttpLog.options[:log_status]
53
- HttpLog::log("[httplog] Response: #{response.body}") if HttpLog.options[:log_response]
52
+ if HttpLog.options[:compact_log]
53
+ HttpLog::log("[httplog] #{req.method} http://#{@address}:#{@port}#{req.path} completed with status code #{response.code} in #{benchmark}")
54
+ else
55
+ HttpLog::log("[httplog] Benchmark: #{benchmark}") if HttpLog.options[:log_benchmark]
56
+ HttpLog::log("[httplog] Status: #{response.code}") if HttpLog.options[:log_status]
57
+ HttpLog::log("[httplog] Response: #{response.body}") if HttpLog.options[:log_response]
58
+ end
54
59
  end
55
-
60
+
56
61
  response
57
62
  end
58
63
 
59
64
  def connect
60
- unless started?
65
+ unless started? || HttpLog.options[:compact_log]
61
66
  HttpLog::log("[httplog] Connecting: #{@address}") if HttpLog.options[:log_connect]
62
67
  end
63
68
  orig_connect
64
69
  end
65
70
  end
66
71
 
67
- end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module HttpLog
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httplog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000 Z
12
+ date: 2012-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70260787628680 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70260787628680
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: ! "Log outgoing HTTP requests made from your application. Helpful for
26
31
  tracking API calls\n of third party gems that don't provide
27
32
  their own log output."
@@ -49,9 +54,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
54
  - - ! '>='
50
55
  - !ruby/object:Gem::Version
51
56
  version: '0'
52
- segments:
53
- - 0
54
- hash: 3192399211165179512
55
57
  required_rubygems_version: !ruby/object:Gem::Requirement
56
58
  none: false
57
59
  requirements:
@@ -60,8 +62,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
62
  version: '0'
61
63
  requirements: []
62
64
  rubyforge_project:
63
- rubygems_version: 1.8.10
65
+ rubygems_version: 1.8.24
64
66
  signing_key:
65
67
  specification_version: 3
66
68
  summary: Logs outgoing Net::HTTP requests.
67
69
  test_files: []
70
+ has_rdoc: