http_logger 0.4.0 → 0.4.1
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.
- data/Readme.md +10 -5
- data/VERSION +1 -1
- data/http_logger.gemspec +3 -3
- data/lib/http_logger.rb +22 -10
- data/spec/http_logger_spec.rb +15 -1
- metadata +4 -4
data/Readme.md
CHANGED
@@ -11,15 +11,20 @@ Simple gem that logs your HTTP api requests just like database queries
|
|
11
11
|
|
12
12
|
## Installation
|
13
13
|
|
14
|
-
|
14
|
+
``` sh
|
15
|
+
gem install http_logger
|
16
|
+
```
|
15
17
|
|
16
18
|
## Usage
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
Net::HTTP.logger = Logger.new(...) # defaults to Rails.logger if Rails is defined
|
21
|
-
Net::HTTP.colorize = true # Default: true
|
20
|
+
``` ruby
|
21
|
+
require 'http_logger'
|
22
22
|
|
23
|
+
HttpLogger.logger = Logger.new(...) # defaults to Rails.logger if Rails is defined
|
24
|
+
HttpLogger.colorize = true # Default: true
|
25
|
+
HttpLogger.ignore = [/newrelic\.com/]
|
26
|
+
HttpLogger.log_headers = false # Default: false
|
27
|
+
```
|
23
28
|
|
24
29
|
## Alternative
|
25
30
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/http_logger.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "http_logger"
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.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 = "2013-04-
|
12
|
+
s.date = "2013-04-26"
|
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
14
|
s.email = "agresso@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
|
|
35
35
|
s.homepage = "http://github.com/bogdan/http_logger"
|
36
36
|
s.licenses = ["MIT"]
|
37
37
|
s.require_paths = ["lib"]
|
38
|
-
s.rubygems_version = "1.8.
|
38
|
+
s.rubygems_version = "1.8.25"
|
39
39
|
s.summary = "Log your http api calls just like SQL queries"
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
data/lib/http_logger.rb
CHANGED
@@ -26,11 +26,13 @@ class HttpLogger
|
|
26
26
|
attr_accessor :log_headers
|
27
27
|
attr_accessor :logger
|
28
28
|
attr_accessor :colorize
|
29
|
+
attr_accessor :ignore
|
29
30
|
end
|
30
31
|
|
31
32
|
self.log_headers = false
|
32
33
|
self.colorize = true
|
33
34
|
self.collapse_body_limit = 5000
|
35
|
+
self.ignore = []
|
34
36
|
|
35
37
|
def self.perform(*args, &block)
|
36
38
|
instance.perform(*args, &block)
|
@@ -63,9 +65,12 @@ class HttpLogger
|
|
63
65
|
protected
|
64
66
|
|
65
67
|
def log_request_url(http, request, start_time)
|
66
|
-
url = "http#{"s" if http.use_ssl?}://#{http.address}:#{http.port}#{request.path}"
|
67
68
|
ofset = Time.now - start_time
|
68
|
-
log("HTTP #{request.method} (%0.2fms)" % (ofset * 1000),
|
69
|
+
log("HTTP #{request.method} (%0.2fms)" % (ofset * 1000), request_url(http, request))
|
70
|
+
end
|
71
|
+
|
72
|
+
def request_url(http, request)
|
73
|
+
URI.decode("http#{"s" if http.use_ssl?}://#{http.address}:#{http.port}#{request.path}")
|
69
74
|
end
|
70
75
|
|
71
76
|
def log_request_headers(request)
|
@@ -105,14 +110,21 @@ class HttpLogger
|
|
105
110
|
end
|
106
111
|
|
107
112
|
def require_logging?(http, request)
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
self.logger && !ignored?(http, request) && (http.started? || fakeweb?(http, request))
|
114
|
+
end
|
115
|
+
|
116
|
+
def ignored?(http, request)
|
117
|
+
url = request_url(http, request)
|
118
|
+
self.class.ignore.any? do |pattern|
|
119
|
+
url =~ pattern
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def fakeweb?(http, request)
|
124
|
+
return false unless defined?(::FakeWeb)
|
125
|
+
uri = ::FakeWeb::Utility.request_uri_as_string(http, request)
|
126
|
+
method = request.method.downcase.to_sym
|
127
|
+
::FakeWeb.registered_uri?(method, uri)
|
116
128
|
end
|
117
129
|
|
118
130
|
def truncate_body(body)
|
data/spec/http_logger_spec.rb
CHANGED
@@ -96,7 +96,6 @@ describe HttpLogger do
|
|
96
96
|
|
97
97
|
context "with long response body" do
|
98
98
|
|
99
|
-
|
100
99
|
let(:url) do
|
101
100
|
FakeWeb.register_uri(:get, "http://github.com", :body => long_body)
|
102
101
|
"http://github.com"
|
@@ -107,4 +106,19 @@ describe HttpLogger do
|
|
107
106
|
it { should include("12,Bonobos,bono@bos.com,tech@bonobos.com,double elimination\n")}
|
108
107
|
|
109
108
|
end
|
109
|
+
|
110
|
+
context "ignore option is set" do
|
111
|
+
|
112
|
+
let(:url) { "http://rpm.newrelic.com/hello/world"}
|
113
|
+
|
114
|
+
before(:each) do
|
115
|
+
HttpLogger.ignore = [/rpm\.newrelic\.com/]
|
116
|
+
end
|
117
|
+
|
118
|
+
it { should be_empty}
|
119
|
+
|
120
|
+
after(:each) do
|
121
|
+
HttpLogger.ignore = []
|
122
|
+
end
|
123
|
+
end
|
110
124
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: debugger
|
@@ -129,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
129
129
|
version: '0'
|
130
130
|
segments:
|
131
131
|
- 0
|
132
|
-
hash: -
|
132
|
+
hash: -725652863842081828
|
133
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
134
|
none: false
|
135
135
|
requirements:
|
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.25
|
142
142
|
signing_key:
|
143
143
|
specification_version: 3
|
144
144
|
summary: Log your http api calls just like SQL queries
|