http_logger 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,9 +2,8 @@ source "http://rubygems.org"
2
2
 
3
3
 
4
4
  group :development do
5
- gem "rspec", "~> 2.3.0"
6
- gem "bundler", "~> 1.0.0"
7
- gem "jeweler", "~> 1.6.0"
8
- gem "rcov", ">= 0"
5
+ gem "rspec"
6
+ gem "bundler"
7
+ gem "jeweler"
9
8
  gem "fakeweb"
10
9
  end
data/Gemfile.lock CHANGED
@@ -1,30 +1,32 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.2)
4
+ diff-lcs (1.1.3)
5
5
  fakeweb (1.3.0)
6
6
  git (1.2.5)
7
- jeweler (1.6.0)
8
- bundler (~> 1.0.0)
7
+ jeweler (1.8.3)
8
+ bundler (~> 1.0)
9
9
  git (>= 1.2.5)
10
10
  rake
11
- rake (0.8.7)
12
- rcov (0.9.9)
13
- rspec (2.3.0)
14
- rspec-core (~> 2.3.0)
15
- rspec-expectations (~> 2.3.0)
16
- rspec-mocks (~> 2.3.0)
17
- rspec-core (2.3.1)
18
- rspec-expectations (2.3.0)
19
- diff-lcs (~> 1.1.2)
20
- rspec-mocks (2.3.0)
11
+ rdoc
12
+ json (1.6.6)
13
+ rake (0.9.2.2)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.9.0)
17
+ rspec-core (~> 2.9.0)
18
+ rspec-expectations (~> 2.9.0)
19
+ rspec-mocks (~> 2.9.0)
20
+ rspec-core (2.9.0)
21
+ rspec-expectations (2.9.1)
22
+ diff-lcs (~> 1.1.3)
23
+ rspec-mocks (2.9.0)
21
24
 
22
25
  PLATFORMS
23
26
  ruby
24
27
 
25
28
  DEPENDENCIES
26
- bundler (~> 1.0.0)
29
+ bundler
27
30
  fakeweb
28
- jeweler (~> 1.6.0)
29
- rcov
30
- rspec (~> 2.3.0)
31
+ jeweler
32
+ rspec
data/Readme.md CHANGED
@@ -6,7 +6,8 @@ Simple gem that logs your HTTP api requests just like database queries
6
6
  ## Screenshot
7
7
 
8
8
  * [Hoptoad](https://github.com/railsware/http_logger/raw/master/screenshots/hoptoad.png)
9
- * [Google](https://github.com/railsware/http_logger/raw/master/screenshots/rails_console.png)
9
+ * [Simple get](https://github.com/railsware/http_logger/raw/master/screenshots/rails_console.png)
10
+ * [Solr](https://github.com/railsware/http_logger/raw/master/screenshots/solr.png)
10
11
 
11
12
  ## Installation
12
13
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
data/http_logger.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{http_logger}
8
- s.version = "0.1.0"
7
+ s.name = "http_logger"
8
+ s.version = "0.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2011-05-08}
13
- s.description = %q{This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file}
14
- s.email = %q{agresso@gmail.com}
12
+ s.date = "2012-04-13"
13
+ s.description = "This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file"
14
+ s.email = "agresso@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt"
17
17
  ]
@@ -28,37 +28,34 @@ Gem::Specification.new do |s|
28
28
  "lib/http_logger.rb",
29
29
  "screenshots/hoptoad.png",
30
30
  "screenshots/rails_console.png",
31
+ "screenshots/solr.png",
31
32
  "spec/http_logger_spec.rb",
32
33
  "spec/spec_helper.rb"
33
34
  ]
34
- s.homepage = %q{http://github.com/bogdan/http_logger}
35
+ s.homepage = "http://github.com/bogdan/http_logger"
35
36
  s.licenses = ["MIT"]
36
37
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.3.7}
38
- s.summary = %q{Log your http api calls just like SQL queries}
38
+ s.rubygems_version = "1.8.11"
39
+ s.summary = "Log your http api calls just like SQL queries"
39
40
 
40
41
  if s.respond_to? :specification_version then
41
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
42
  s.specification_version = 3
43
43
 
44
44
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
46
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
48
- s.add_development_dependency(%q<rcov>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>, [">= 0"])
46
+ s.add_development_dependency(%q<bundler>, [">= 0"])
47
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
49
48
  s.add_development_dependency(%q<fakeweb>, [">= 0"])
50
49
  else
51
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
52
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
54
- s.add_dependency(%q<rcov>, [">= 0"])
50
+ s.add_dependency(%q<rspec>, [">= 0"])
51
+ s.add_dependency(%q<bundler>, [">= 0"])
52
+ s.add_dependency(%q<jeweler>, [">= 0"])
55
53
  s.add_dependency(%q<fakeweb>, [">= 0"])
56
54
  end
57
55
  else
58
- s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
- s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
56
+ s.add_dependency(%q<rspec>, [">= 0"])
57
+ s.add_dependency(%q<bundler>, [">= 0"])
58
+ s.add_dependency(%q<jeweler>, [">= 0"])
62
59
  s.add_dependency(%q<fakeweb>, [">= 0"])
63
60
  end
64
61
  end
data/lib/http_logger.rb CHANGED
@@ -7,6 +7,7 @@ require 'net/http'
7
7
  # == Setup logger
8
8
  #
9
9
  # Net::HTTP.logger = Logger.new('/tmp/all.log')
10
+ # Net::HTTP.log_headers = true
10
11
  #
11
12
  # == Do request
12
13
  #
@@ -18,10 +19,12 @@ require 'net/http'
18
19
  class Net::HTTP
19
20
 
20
21
  class << self
22
+ attr_accessor :log_headers
21
23
  attr_accessor :logger
22
24
  attr_accessor :colorize
23
25
  end
24
26
 
27
+ self.log_headers = false
25
28
  self.colorize = true
26
29
 
27
30
 
@@ -36,9 +39,13 @@ class Net::HTTP
36
39
  url = "http#{"s" if self.use_ssl?}://#{self.address}:#{self.port}#{request.path}"
37
40
  ofset = Time.now - time
38
41
  log("HTTP #{request.method} (%0.2fms)" % (ofset * 1000), url)
39
- log("POST params", request.body) if request.is_a?(::Net::HTTP::Post)
42
+ request.each_capitalized { |k,v| log("HTTP request header", "#{k}: #{v}") } if self.class.log_headers
43
+ if request.is_a?(::Net::HTTP::Post) || request.is_a?(::Net::HTTP::Put)
44
+ log("#{request.class.to_s.upcase} params", request.body)
45
+ end
40
46
  if defined?(response) && response
41
47
  log("Response status", "#{response.class} (#{response.code})")
48
+ response.each_capitalized { |k,v| log("HTTP response header", "#{k}: #{v}") } if self.class.log_headers
42
49
  body = response.body
43
50
  log("Response body", body) unless body.is_a?(Net::ReadAdapter)
44
51
  end
@@ -47,9 +54,9 @@ class Net::HTTP
47
54
 
48
55
  def require_logging?(request)
49
56
  fakeweb = if defined?(::FakeWeb)
50
- uri = FakeWeb::Utility.request_uri_as_string(self, request)
57
+ uri = ::FakeWeb::Utility.request_uri_as_string(self, request)
51
58
  method = request.method.downcase.to_sym
52
- FakeWeb.registered_uri?(method, uri)
59
+ ::FakeWeb.registered_uri?(method, uri)
53
60
  else
54
61
  false
55
62
  end
Binary file
@@ -1,24 +1,60 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
+ require 'fakeweb'
3
+ require "uri"
2
4
 
3
5
  describe "HttpLogger" do
4
6
 
7
+ before do
8
+ # flush log
9
+ f = File.open(LOGFILE, "w")
10
+ f.close
11
+ end
12
+
13
+ let(:url) { "http://google.com/" }
14
+ let(:uri) { URI.parse("http://google.com/") }
15
+ let(:request) do
16
+ Net::HTTP.get_response(uri)
17
+ end
18
+
5
19
  subject do
6
- uri = URI.parse("http://google.com/")
7
- response = Net::HTTP.get_response(uri)
20
+ request
8
21
  File.read(LOGFILE)
9
22
  end
10
23
 
11
24
  it { should_not be_empty }
12
25
 
13
- context "with FakeWeb" do
14
- before(:all) do
15
- require 'fakeweb'
26
+ context "when headers logging is on" do
27
+
28
+ before(:each) do
29
+ Net::HTTP.log_headers = true
16
30
  end
17
- it {should_not be_empty}
18
31
 
19
- after(:all) do
20
- Object.send(:remove_const, "FakeWeb")
32
+ it { should include("HTTP response header") }
33
+ it { should include("HTTP request header") }
34
+
35
+ after(:each) do
36
+ Net::HTTP.log_headers = false
21
37
  end
22
38
 
23
39
  end
40
+
41
+ describe "post request" do
42
+ let(:request) do
43
+ Net::HTTP.post_form(uri, {:a => 'hello', :b => 1})
44
+ end
45
+
46
+ it {should include("POST params")}
47
+ it {should include("a=hello&b=1")}
48
+ end
49
+ describe "put request" do
50
+ let(:request) do
51
+ http = Net::HTTP.new(uri.host, uri.port)
52
+ request = Net::HTTP::Put.new(uri.path)
53
+ request.set_form_data(:a => 'hello', :b => 1)
54
+ http.request(request)
55
+ end
56
+
57
+ it {should include("a=hello&b=1")}
58
+ it {should include("PUT params")}
59
+ end
24
60
  end
metadata CHANGED
@@ -1,108 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: http_logger
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Bogdan Gusiev
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-05-08 00:00:00 +03:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rspec
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &14480200 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 2
31
- - 3
32
- - 0
33
- version: 2.3.0
34
- prerelease: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
35
22
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: *14480200
25
+ - !ruby/object:Gem::Dependency
38
26
  name: bundler
39
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &14479200 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 1
47
- - 0
48
- - 0
49
- version: 1.0.0
50
- prerelease: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
51
33
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
34
+ prerelease: false
35
+ version_requirements: *14479200
36
+ - !ruby/object:Gem::Dependency
54
37
  name: jeweler
55
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &15004260 !ruby/object:Gem::Requirement
56
39
  none: false
57
- requirements:
58
- - - ~>
59
- - !ruby/object:Gem::Version
60
- hash: 15
61
- segments:
62
- - 1
63
- - 6
64
- - 0
65
- version: 1.6.0
66
- prerelease: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
67
44
  type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rcov
71
- requirement: &id004 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 3
77
- segments:
78
- - 0
79
- version: "0"
80
45
  prerelease: false
81
- type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *15004260
47
+ - !ruby/object:Gem::Dependency
84
48
  name: fakeweb
85
- requirement: &id005 !ruby/object:Gem::Requirement
49
+ requirement: &15003560 !ruby/object:Gem::Requirement
86
50
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
94
- prerelease: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
95
55
  type: :development
96
- version_requirements: *id005
97
- description: This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file
56
+ prerelease: false
57
+ version_requirements: *15003560
58
+ description: This gem keep an eye on every Net::HTTP library usage and dump all request
59
+ and response data to the log file
98
60
  email: agresso@gmail.com
99
61
  executables: []
100
-
101
62
  extensions: []
102
-
103
- extra_rdoc_files:
63
+ extra_rdoc_files:
104
64
  - LICENSE.txt
105
- files:
65
+ files:
106
66
  - .document
107
67
  - .rspec
108
68
  - Gemfile
@@ -115,41 +75,35 @@ files:
115
75
  - lib/http_logger.rb
116
76
  - screenshots/hoptoad.png
117
77
  - screenshots/rails_console.png
78
+ - screenshots/solr.png
118
79
  - spec/http_logger_spec.rb
119
80
  - spec/spec_helper.rb
120
- has_rdoc: true
121
81
  homepage: http://github.com/bogdan/http_logger
122
- licenses:
82
+ licenses:
123
83
  - MIT
124
84
  post_install_message:
125
85
  rdoc_options: []
126
-
127
- require_paths:
86
+ require_paths:
128
87
  - lib
129
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
130
89
  none: false
131
- requirements:
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- hash: 3
135
- segments:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
136
95
  - 0
137
- version: "0"
138
- required_rubygems_version: !ruby/object:Gem::Requirement
96
+ hash: 734133790092156030
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
98
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- hash: 3
144
- segments:
145
- - 0
146
- version: "0"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
147
103
  requirements: []
148
-
149
104
  rubyforge_project:
150
- rubygems_version: 1.3.7
105
+ rubygems_version: 1.8.11
151
106
  signing_key:
152
107
  specification_version: 3
153
108
  summary: Log your http api calls just like SQL queries
154
109
  test_files: []
155
-