http_logger 0.4.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42d833f6603f1388a733dcc558c3a8e23004ac2e
4
- data.tar.gz: 20d21f3e5dfa0413809092499c4769bf7aa2d303
3
+ metadata.gz: 9d99effbf8fa7d49cb7db951595025c3a9f2f6fe
4
+ data.tar.gz: 85a8d71ee430d2652c4655eb553bc865c39ef746
5
5
  SHA512:
6
- metadata.gz: fef1b14a5d854fab100449356b60539ed40076f61df7a4e946fb14b1e8effc50a48ef633876f02249fa5f0e5bb47ef4809e638b7c70ba27351446702fddb59aa
7
- data.tar.gz: 5b063e5050d9925a12d19ffa5efbe524f0fb01f27d08c2161c5b0d7cbd1dd90d2719f857ca6693b7344bd53235be25f85a7400988210a11df1ef7f4dfb9c3a5e
6
+ metadata.gz: 7a6704abca3ff95642f1c4f4e527030c11628328104a7fe510c0641e2dbf3c615820bf98f1ab567c338c823a793691ba3dfca7215306c50d7364f72ff71d624b
7
+ data.tar.gz: 996ca33603a94dfbbbc7665214fc6745ca05f6720d6284a02ebda9b12154771927dae580e0b85611134250d1e597b5358bc32e8dd17c30417c9d0dcb0de1dc0b
data/Readme.md CHANGED
@@ -24,6 +24,9 @@ HttpLogger.logger = Logger.new(...) # defaults to Rails.logger if Rails is defin
24
24
  HttpLogger.colorize = true # Default: true
25
25
  HttpLogger.ignore = [/newrelic\.com/]
26
26
  HttpLogger.log_headers = false # Default: false
27
+ HttpLogger.log_request_body = false # Default: true
28
+ HttpLogger.log_response_body = false # Default: true
29
+ HttpLogger.level = :info # Desired log level as a symbol. Default: :debug
27
30
  ```
28
31
 
29
32
  ## Alternative
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.3
1
+ 0.5.0
@@ -2,16 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: http_logger 0.4.3 ruby lib
5
+ # stub: http_logger 0.5.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "http_logger"
9
- s.version = "0.4.3"
9
+ s.version = "0.5.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
12
  s.authors = ["Bogdan Gusiev"]
14
- s.date = "2014-04-04"
13
+ s.date = "2014-10-12"
15
14
  s.description = "This gem keep an eye on every Net::HTTP library usage and dump all request and response data to the log file"
16
15
  s.email = "agresso@gmail.com"
17
16
  s.extra_rdoc_files = [
@@ -36,7 +35,8 @@ Gem::Specification.new do |s|
36
35
  ]
37
36
  s.homepage = "http://github.com/railsware/http_logger"
38
37
  s.licenses = ["MIT"]
39
- s.rubygems_version = "2.2.2"
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "2.1.10"
40
40
  s.summary = "Log your http api calls just like SQL queries"
41
41
 
42
42
  if s.respond_to? :specification_version then
@@ -25,15 +25,21 @@ class HttpLogger
25
25
  class << self
26
26
  attr_accessor :collapse_body_limit
27
27
  attr_accessor :log_headers
28
+ attr_accessor :log_request_body
29
+ attr_accessor :log_response_body
28
30
  attr_accessor :logger
29
31
  attr_accessor :colorize
30
32
  attr_accessor :ignore
33
+ attr_accessor :level
31
34
  end
32
35
 
33
36
  self.log_headers = false
37
+ self.log_request_body = true
38
+ self.log_response_body = true
34
39
  self.colorize = true
35
40
  self.collapse_body_limit = 5000
36
41
  self.ignore = []
42
+ self.level = :debug
37
43
 
38
44
  def self.perform(*args, &block)
39
45
  instance.perform(*args, &block)
@@ -83,9 +89,11 @@ class HttpLogger
83
89
  HTTP_METHODS_WITH_BODY = Set.new(%w(POST PUT GET))
84
90
 
85
91
  def log_request_body(request)
86
- if HTTP_METHODS_WITH_BODY.include?(request.method)
87
- if (body = request.body) && !body.empty?
88
- log("Request body", truncate_body(body))
92
+ if self.class.log_request_body
93
+ if HTTP_METHODS_WITH_BODY.include?(request.method)
94
+ if (body = request.body) && !body.empty?
95
+ log("Request body", truncate_body(body))
96
+ end
89
97
  end
90
98
  end
91
99
  end
@@ -101,11 +109,13 @@ class HttpLogger
101
109
  end
102
110
 
103
111
  def log_response_body(body)
104
- if body.is_a?(Net::ReadAdapter)
105
- log("Response body", "<impossible to log>")
106
- else
107
- if body && !body.empty?
108
- log("Response body", truncate_body(body))
112
+ if self.class.log_response_body
113
+ if body.is_a?(Net::ReadAdapter)
114
+ log("Response body", "<impossible to log>")
115
+ else
116
+ if body && !body.empty?
117
+ log("Response body", truncate_body(body))
118
+ end
109
119
  end
110
120
  end
111
121
  end
@@ -139,9 +149,8 @@ class HttpLogger
139
149
  end
140
150
  end
141
151
 
142
-
143
152
  def log(message, dump)
144
- self.logger.debug(format_log_entry(message, dump))
153
+ self.logger.send(self.class.level, format_log_entry(message, dump))
145
154
  end
146
155
 
147
156
  def format_log_entry(message, dump = nil)
@@ -206,5 +215,3 @@ if defined?(Rails)
206
215
  end
207
216
  end
208
217
  end
209
-
210
-
@@ -70,6 +70,7 @@ describe HttpLogger do
70
70
  end
71
71
 
72
72
  end
73
+
73
74
  describe "put request" do
74
75
  let(:request) do
75
76
  http = Net::HTTP.new(uri.host, uri.port)
@@ -94,6 +95,23 @@ describe HttpLogger do
94
95
  it {should include("a=hello&b=1")}
95
96
  end
96
97
 
98
+ context "when request body logging is off" do
99
+
100
+ before(:each) do
101
+ HttpLogger.log_request_body = false
102
+ end
103
+
104
+ let(:request) do
105
+ Net::HTTP.post_form(uri, {})
106
+ end
107
+
108
+ it { should_not include("Request body") }
109
+
110
+ after(:each) do
111
+ HttpLogger.log_request_body = true
112
+ end
113
+ end
114
+
97
115
  context "with long response body" do
98
116
 
99
117
  let(:url) do
@@ -107,6 +125,24 @@ describe HttpLogger do
107
125
 
108
126
  end
109
127
 
128
+ context "when response body logging is off" do
129
+
130
+ before(:each) do
131
+ HttpLogger.log_response_body = false
132
+ end
133
+
134
+ let(:url) do
135
+ FakeWeb.register_uri(:get, "http://github.com", :body => long_body)
136
+ "http://github.com"
137
+ end
138
+
139
+ it { should_not include("Response body") }
140
+
141
+ after(:each) do
142
+ HttpLogger.log_response_body = true
143
+ end
144
+ end
145
+
110
146
  context "ignore option is set" do
111
147
 
112
148
  let(:url) { "http://rpm.newrelic.com/hello/world"}
@@ -121,4 +157,19 @@ describe HttpLogger do
121
157
  HttpLogger.ignore = []
122
158
  end
123
159
  end
160
+
161
+ context "when level is set" do
162
+
163
+ let(:url) { "http://rpm.newrelic.com/hello/world"}
164
+
165
+ before(:each) do
166
+ HttpLogger.level = :info
167
+ end
168
+
169
+ it { should_not be_empty }
170
+
171
+ after(:each) do
172
+ HttpLogger.level = :debug
173
+ end
174
+ end
124
175
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-04 00:00:00.000000000 Z
11
+ date: 2014-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: debugger
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: jeweler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fakeweb
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: This gem keep an eye on every Net::HTTP library usage and dump all request
@@ -88,8 +88,8 @@ extensions: []
88
88
  extra_rdoc_files:
89
89
  - LICENSE.txt
90
90
  files:
91
- - ".document"
92
- - ".rspec"
91
+ - .document
92
+ - .rspec
93
93
  - Gemfile
94
94
  - Gemfile.lock
95
95
  - LICENSE.txt
@@ -113,17 +113,17 @@ require_paths:
113
113
  - lib
114
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - '>='
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  requirements:
121
- - - ">="
121
+ - - '>='
122
122
  - !ruby/object:Gem::Version
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.2.2
126
+ rubygems_version: 2.1.10
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: Log your http api calls just like SQL queries