http_logger 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/Readme.md +4 -0
- data/VERSION +1 -1
- data/http_logger.gemspec +5 -2
- data/lib/http_logger.rb +13 -1
- data/spec/http_logger_spec.rb +16 -3
- metadata +33 -19
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,6 +2,7 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
diff-lcs (1.1.2)
|
5
|
+
fakeweb (1.3.0)
|
5
6
|
git (1.2.5)
|
6
7
|
jeweler (1.6.0)
|
7
8
|
bundler (~> 1.0.0)
|
@@ -23,6 +24,7 @@ PLATFORMS
|
|
23
24
|
|
24
25
|
DEPENDENCIES
|
25
26
|
bundler (~> 1.0.0)
|
27
|
+
fakeweb
|
26
28
|
jeweler (~> 1.6.0)
|
27
29
|
rcov
|
28
30
|
rspec (~> 2.3.0)
|
data/Readme.md
CHANGED
@@ -24,3 +24,7 @@ Simple gem that logs your HTTP api requests just like database queries
|
|
24
24
|
|
25
25
|
Net::HTTP has a builtin logger that can be set via \#set\_debug\_output.
|
26
26
|
This method is only available at the instance level and it is not always accessible if used inside of a library. Also output of builtin debugger is not formed well for API debug purposes.
|
27
|
+
|
28
|
+
## Integration
|
29
|
+
|
30
|
+
If you are using Net::HTTP#request hackers like FakeWeb make sure you require http\_logger after all others because http\_logger always calls "super", rather than others.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/http_logger.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{http_logger}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
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-
|
12
|
+
s.date = %q{2011-05-08}
|
13
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
14
|
s.email = %q{agresso@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -46,17 +46,20 @@ Gem::Specification.new do |s|
|
|
46
46
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
47
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
48
48
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
49
50
|
else
|
50
51
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
51
52
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
52
53
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
53
54
|
s.add_dependency(%q<rcov>, [">= 0"])
|
55
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
54
56
|
end
|
55
57
|
else
|
56
58
|
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
57
59
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
60
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
59
61
|
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
data/lib/http_logger.rb
CHANGED
@@ -32,7 +32,7 @@ class Net::HTTP
|
|
32
32
|
response = request_without_logging(request, body, &block)
|
33
33
|
response
|
34
34
|
ensure
|
35
|
-
if self.
|
35
|
+
if self.require_logging?(request)
|
36
36
|
url = "http#{"s" if self.use_ssl?}://#{self.address}:#{self.port}#{request.path}"
|
37
37
|
ofset = Time.now - time
|
38
38
|
log("HTTP #{request.method} (%0.2fms)" % (ofset * 1000), url)
|
@@ -45,6 +45,18 @@ class Net::HTTP
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def require_logging?(request)
|
49
|
+
fakeweb = if defined?(::FakeWeb)
|
50
|
+
uri = FakeWeb::Utility.request_uri_as_string(self, request)
|
51
|
+
method = request.method.downcase.to_sym
|
52
|
+
FakeWeb.registered_uri?(method, uri)
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
56
|
+
self.logger && (self.started? || fakeweb)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
48
60
|
protected
|
49
61
|
def log(message, dump)
|
50
62
|
self.logger.debug(format_log_entry(message, dump))
|
data/spec/http_logger_spec.rb
CHANGED
@@ -1,11 +1,24 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe "HttpLogger" do
|
4
|
-
it "should log request" do
|
5
|
-
uri = URI.parse("http://google.com/")
|
6
4
|
|
5
|
+
subject do
|
6
|
+
uri = URI.parse("http://google.com/")
|
7
7
|
response = Net::HTTP.get_response(uri)
|
8
|
-
File.read(LOGFILE)
|
8
|
+
File.read(LOGFILE)
|
9
|
+
end
|
10
|
+
|
11
|
+
it { should_not be_empty }
|
12
|
+
|
13
|
+
context "with FakeWeb" do
|
14
|
+
before(:all) do
|
15
|
+
require 'fakeweb'
|
16
|
+
end
|
17
|
+
it {should_not be_empty}
|
9
18
|
|
19
|
+
after(:all) do
|
20
|
+
Object.send(:remove_const, "FakeWeb")
|
21
|
+
end
|
22
|
+
|
10
23
|
end
|
11
24
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bogdan Gusiev
|
@@ -15,14 +15,12 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-08 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: rspec
|
23
|
-
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
24
|
none: false
|
27
25
|
requirements:
|
28
26
|
- - ~>
|
@@ -33,12 +31,12 @@ dependencies:
|
|
33
31
|
- 3
|
34
32
|
- 0
|
35
33
|
version: 2.3.0
|
36
|
-
|
34
|
+
prerelease: false
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: bundler
|
39
|
-
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
40
|
none: false
|
43
41
|
requirements:
|
44
42
|
- - ~>
|
@@ -49,12 +47,12 @@ dependencies:
|
|
49
47
|
- 0
|
50
48
|
- 0
|
51
49
|
version: 1.0.0
|
52
|
-
|
50
|
+
prerelease: false
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: jeweler
|
55
|
-
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
58
56
|
none: false
|
59
57
|
requirements:
|
60
58
|
- - ~>
|
@@ -65,12 +63,26 @@ dependencies:
|
|
65
63
|
- 6
|
66
64
|
- 0
|
67
65
|
version: 1.6.0
|
68
|
-
|
66
|
+
prerelease: false
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
|
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"
|
72
80
|
prerelease: false
|
73
|
-
|
81
|
+
type: :development
|
82
|
+
version_requirements: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakeweb
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
74
86
|
none: false
|
75
87
|
requirements:
|
76
88
|
- - ">="
|
@@ -79,7 +91,9 @@ dependencies:
|
|
79
91
|
segments:
|
80
92
|
- 0
|
81
93
|
version: "0"
|
82
|
-
|
94
|
+
prerelease: false
|
95
|
+
type: :development
|
96
|
+
version_requirements: *id005
|
83
97
|
description: This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file
|
84
98
|
email: agresso@gmail.com
|
85
99
|
executables: []
|