httplog 1.3.2 → 1.3.3

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
  SHA256:
3
- metadata.gz: a5d566f72650b5c55a8ae3dfc25dd551b9779eccce87cd307b31a0e134e25443
4
- data.tar.gz: 6842fc573dfe4dc2e747b4c480b2a03c547813a05fc0bec13263af20c8a599b5
3
+ metadata.gz: 899f0ffc584e0b7c88daa0e6895502f4d1a20d850d59ae1483de9dac829346f3
4
+ data.tar.gz: ee045f1978c1955ef213382b166bcf6e824fe42c352704476b3683ef0c495f54
5
5
  SHA512:
6
- metadata.gz: 61809a350f2a87225e275d49691539a10081ae8e4457c772cdc056fc9788c2c11913bf63647e76b3d5b81da2c6aaf83e4405e8224adc1120e04eabedd8f3b541
7
- data.tar.gz: ac37ba6e331d1a553925b13361ea786728e20f608bddb9f3037b9fbb346ece62577def82c18319e9ae397e00c5bcccfd0b7637ea642c0659118c94689dfa0c37
6
+ metadata.gz: a7a9ae16ba3ff2391021c8284d4e0ff43c40b30bfed7f33d8f288312410a527dec550af3eb993c355e8e6d07132fa46378b09dc6535ffdea00650d256e34c9c6
7
+ data.tar.gz: 58f22a5832993eefef75b2a2a3f9e6ab6c41286553b404b44e2df8fbee3a6623116b7729222a3ef842380969ea8edc53b9dd4b93755b612594b1f473560d2b3f
@@ -1,3 +1,7 @@
1
+ ## 1.3.3 - 2019-11-14
2
+
3
+ * [#83](https://github.com/trusche/httplog/pull/83) Support for graylog
4
+
1
5
  ## 1.3.1 - 2019-06-07
2
6
 
3
7
  * [#76](https://github.com/trusche/httplog/pull/76) Added configurable logger method
data/README.md CHANGED
@@ -76,6 +76,9 @@ HttpLog.configure do |config|
76
76
  # You can also log in JSON format
77
77
  config.json_log = false
78
78
 
79
+ # For Graylog you can set this to `true`
80
+ config.graylog = false
81
+
79
82
  # Prettify the output - see below
80
83
  config.color = false
81
84
 
@@ -118,6 +121,18 @@ HttpLog.configure do |config|
118
121
  end
119
122
  ```
120
123
 
124
+ If you use Graylog and want to use its search features such as "rounded_benchmark:>1 AND method:PUT",
125
+ you can use this configuration:
126
+
127
+ ```ruby
128
+ HttpLog.configure do |config|
129
+ config.logger = <your GELF::Logger>
130
+ config.logger_method = :add
131
+ config.severity = GELF::Levels::DEBUG
132
+ config.graylog = true
133
+ end
134
+ ```
135
+
121
136
  For more color options please refer to the [rainbow documentation](https://github.com/sickill/rainbow)
122
137
 
123
138
  ### Compact logging
@@ -232,19 +247,3 @@ This will launch a simple rack server on port 9292 and run all tests locally aga
232
247
  If you have any issues with or feature requests for httplog,
233
248
  please [open an issue](https://github.com/trusche/httplog/issues) on GitHub
234
249
  or fork the project and send a pull request. **Please include passing specs with all pull requests.**
235
-
236
- ### Contributors
237
-
238
- Thanks to these fine folks for contributing pull requests:
239
-
240
- * [Doug Johnston](https://github.com/dougjohnston)
241
- * [Eric Cohen](https://github.com/eirc)
242
- * [Nikos Dimitrakopoulos](https://github.com/nikosd)
243
- * [Marcos Hack](https://github.com/marcoshack)
244
- * [Andrew Hammond](https://github.com/andrhamm)
245
- * [Chris Keele](https://github.com/christhekeele)
246
- * [Ryan Souza](https://github.com/ryansouza)
247
- * [Ilya Bondarenko](https://github.com/sedx)
248
- * [Kostas Zacharakis](https://github.com/kzacharakis)
249
- * [Yuri Smirnov](https://github.com/tycooon)
250
- * [Manuel Bustillo Alonso](https://github.com/bustikiller)
@@ -28,7 +28,7 @@ Gem::Specification.new do |gem|
28
28
  gem.add_development_dependency 'excon', ['~> 0.60']
29
29
  gem.add_development_dependency 'faraday', ['~> 0.14']
30
30
  gem.add_development_dependency 'guard-rspec', ['~> 4.7']
31
- gem.add_development_dependency 'http', ['~> 3.0']
31
+ gem.add_development_dependency 'http', ['~> 4.0']
32
32
  gem.add_development_dependency 'httparty', ['~> 0.16']
33
33
  gem.add_development_dependency 'httpclient', ['~> 2.8']
34
34
  gem.add_development_dependency 'listen', ['~> 3.0']
@@ -5,6 +5,7 @@ module HttpLog
5
5
  attr_accessor :enabled,
6
6
  :compact_log,
7
7
  :json_log,
8
+ :graylog,
8
9
  :logger,
9
10
  :logger_method,
10
11
  :severity,
@@ -28,6 +29,7 @@ module HttpLog
28
29
  @enabled = true
29
30
  @compact_log = false
30
31
  @json_log = false
32
+ @graylog = false
31
33
  @logger = Logger.new($stdout)
32
34
  @logger_method = :log
33
35
  @severity = Logger::Severity::DEBUG
@@ -31,6 +31,8 @@ module HttpLog
31
31
  def call(options = {})
32
32
  if config.json_log
33
33
  log_json(options)
34
+ elsif config.graylog
35
+ log_graylog(options)
34
36
  elsif config.compact_log
35
37
  log_compact(options[:method], options[:url], options[:response_code], options[:benchmark])
36
38
  else
@@ -111,7 +113,7 @@ module HttpLog
111
113
 
112
114
  if body.is_a?(Net::ReadAdapter)
113
115
  # open-uri wraps the response in a Net::ReadAdapter that defers reading
114
- # the content, so the reponse body is not available here.
116
+ # the content, so the response body is not available here.
115
117
  raise BodyParsingError, '(not available yet)'
116
118
  end
117
119
 
@@ -147,38 +149,6 @@ module HttpLog
147
149
  log("#{method.to_s.upcase} #{masked(uri)} completed with status code #{status} in #{seconds.to_f.round(6)} seconds")
148
150
  end
149
151
 
150
- def log_json(data = {})
151
- return unless config.json_log
152
-
153
- data[:response_code] = transform_response_code(data[:response_code]) if data[:response_code].is_a?(Symbol)
154
-
155
- parsed_body = begin
156
- parse_body(data[:response_body], data[:encoding], data[:content_type])
157
- rescue BodyParsingError => e
158
- e.message
159
- end
160
-
161
- if config.compact_log
162
- log({
163
- method: data[:method].to_s.upcase,
164
- url: masked(data[:url]),
165
- response_code: data[:response_code].to_i,
166
- benchmark: data[:benchmark]
167
- }.to_json)
168
- else
169
- log({
170
- method: data[:method].to_s.upcase,
171
- url: masked(data[:url]),
172
- request_body: masked(data[:request_body]),
173
- request_headers: masked(data[:request_headers].to_h),
174
- response_code: data[:response_code].to_i,
175
- response_body: parsed_body,
176
- response_headers: data[:response_headers].to_h,
177
- benchmark: data[:benchmark]
178
- }.to_json)
179
- end
180
- end
181
-
182
152
  def transform_response_code(response_code_name)
183
153
  Rack::Utils::HTTP_STATUS_CODES.detect { |_k, v| v.to_s.casecmp(response_code_name.to_s).zero? }.first
184
154
  end
@@ -199,6 +169,50 @@ module HttpLog
199
169
 
200
170
  private
201
171
 
172
+ def log_json(data = {})
173
+ return unless config.json_log
174
+
175
+ log(json_payload(data).to_json)
176
+ end
177
+
178
+ def log_graylog(data = {})
179
+ result = json_payload(data)
180
+
181
+ result[:rounded_benchmark] = data[:benchmark].round
182
+ result[:short_message] = result.delete(:url)
183
+ config.logger.public_send(config.logger_method, config.severity, result)
184
+ end
185
+
186
+ def json_payload(data = {})
187
+ data[:response_code] = transform_response_code(data[:response_code]) if data[:response_code].is_a?(Symbol)
188
+
189
+ parsed_body = begin
190
+ parse_body(data[:response_body], data[:encoding], data[:content_type])
191
+ rescue BodyParsingError => e
192
+ e.message
193
+ end
194
+
195
+ if config.compact_log
196
+ {
197
+ method: data[:method].to_s.upcase,
198
+ url: masked(data[:url]),
199
+ response_code: data[:response_code].to_i,
200
+ benchmark: data[:benchmark]
201
+ }
202
+ else
203
+ {
204
+ method: data[:method].to_s.upcase,
205
+ url: masked(data[:url]),
206
+ request_body: masked(data[:request_body]),
207
+ request_headers: masked(data[:request_headers].to_h),
208
+ response_code: data[:response_code].to_i,
209
+ response_body: parsed_body,
210
+ response_headers: data[:response_headers].to_h,
211
+ benchmark: data[:benchmark]
212
+ }
213
+ end
214
+ end
215
+
202
216
  def masked(msg, key=nil)
203
217
  return msg if config.filter_parameters.empty?
204
218
  return msg if msg.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HttpLog
4
- VERSION = '1.3.2'.freeze
4
+ VERSION = '1.3.3'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httplog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thilo Rusche
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-24 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ethon
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '4.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
- version: '3.0'
82
+ version: '4.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: httparty
85
85
  requirement: !ruby/object:Gem::Requirement