httplog 1.4.2 → 1.4.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: 5332ba82035e300b5010a5cbcb125d9c90e083a405c43d1be8df1d626fc40fe1
4
- data.tar.gz: 9692d53da3306a12bb14128f8365a9d7524fe6d443474c3dbdc11c21a8f3f6e9
3
+ metadata.gz: 9ce910d7c04847c28f836de26906c0c50aa4642b553b298d15067bf6ee25db56
4
+ data.tar.gz: 8600e756f28e033b6e39ac91235f69bf772fe467b05040d88c02ce54e982ef0b
5
5
  SHA512:
6
- metadata.gz: 7829d7f38262b59ac69ae08e638aad00315322025fed502abf50e4ca468ea4286473c54984277ec98d436ff04fc86157ff38e5e529ec6ee8a9bef5a362f80e48
7
- data.tar.gz: 4d0ccb0d024d21de6dcc9d116353810cf2e8adbc936c9b9ecbd38887931851555c19eb2756b7f43f298b9f7d6cc855322d75f4c473d813c35cc574c63cdb9ae0
6
+ metadata.gz: 6a76055079c7bfa4a229fda0861f90276c94cb64859ae7ce3c269e86656f3ad69fb3d5e8ed7eb2b82e9fe1facb0a73619951f099aafbbac7b0b503a52eb21046
7
+ data.tar.gz: f541eec119d175cc50563bc2673d60dae6246a43bcf570f9fe4db9a6295697ea94f7ffddb709aa8c9d0264f274f48c42bca3322d3364c1edd47298a984421363
@@ -1,3 +1,11 @@
1
+ ## 1.4.3 - 2020-06-10
2
+
3
+ * Masking `password` parameter by default... doh.
4
+
5
+ ## 1.4.2 - 2020-02-09
6
+
7
+ * Rollback of the previous two releases due to bugs introduced there.
8
+
1
9
  ## 1.4.1 - 2020-02-08 - YANKED
2
10
 
3
11
  * [#91](https://github.com/trusche/httplog/pull/91) Fixed bug returning empty response with HTTP gem
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  ## httplog
2
2
 
3
- **VERSION 1.4.0 and 1.4.1 HAVE BEEN YANKED** from rubygems.org due to [this issue](https://github.com/trusche/httplog/issues/89), please update to version 1.4.2. Sorry about that...
3
+ **VERSION 1.4.0 and 1.4.1 HAVE BEEN YANKED** from rubygems.org due to [this issue](https://github.com/trusche/httplog/issues/89), please update to version 1.4.2 or higher. Sorry about that...
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/httplog.svg)](http://badge.fury.io/rb/httplog) [![Build Status](https://travis-ci.org/trusche/httplog.svg?branch=master)](https://travis-ci.org/trusche/httplog) [![Code Climate](https://codeclimate.com/github/trusche/httplog.svg)](https://codeclimate.com/github/trusche/httplog)
6
6
  [![Release Version](https://img.shields.io/github/release/trusche/httplog.svg)](https://img.shields.io/github/release/trusche/httplog.svg)
7
+ <a href="https://www.bearer.sh?ref=httplog"><img src="/bearer-badge.png" height="20px"/></a>
7
8
 
8
9
  Log outgoing HTTP requests made from your application. Helps with debugging pesky API error responses, or just generally understanding what's going on under the hood.
9
10
 
10
- Requires ruby >= 2.4.
11
+ Requires ruby >= 2.5
11
12
 
12
13
  This gem works with the following ruby modules and libraries:
13
14
 
@@ -31,6 +32,10 @@ This is very much a development and debugging tool; it is **not recommended** to
31
32
  use this in a production environment as it is monkey-patching the respective HTTP implementations.
32
33
  You have been warned - use at your own risk.
33
34
 
35
+ Httplog is kindly sponsored by <a href="https://www.bearer.sh?ref=httplog">Bearer.sh</a> - go check them out please!
36
+
37
+ <a href="https://www.bearer.sh?ref=httplog"><img src="/bearer-sponsor.png" height="72px" /></a>
38
+
34
39
  ### Installation
35
40
 
36
41
  gem install httplog
@@ -78,9 +83,6 @@ HttpLog.configure do |config|
78
83
  # You can also log in JSON format
79
84
  config.json_log = false
80
85
 
81
- # For Graylog you can set this to `true`
82
- config.graylog = false
83
-
84
86
  # Prettify the output - see below
85
87
  config.color = false
86
88
 
@@ -96,6 +98,9 @@ HttpLog.configure do |config|
96
98
  # to parse JSON responses
97
99
  config.json_parser = JSON
98
100
 
101
+ # When using graylog, you can supply a formatter here - see below for details
102
+ config.graylog_formatter = nil
103
+
99
104
  # Mask the values of sensitive request parameters
100
105
  config.filter_parameters = %w[password]
101
106
  end
@@ -131,19 +136,38 @@ HttpLog.configure do |config|
131
136
  end
132
137
  ```
133
138
 
139
+ For more color options please refer to the [rainbow documentation](https://github.com/sickill/rainbow)
140
+
141
+ ### Graylog logging
142
+
134
143
  If you use Graylog and want to use its search features such as "benchmark:>1 AND method:PUT",
135
144
  you can use this configuration:
136
145
 
137
146
  ```ruby
147
+ FORMATTER = Lograge::Formatters::KeyValue.new
148
+
138
149
  HttpLog.configure do |config|
139
- config.logger = <your GELF::Logger>
140
- config.logger_method = :add
141
- config.severity = GELF::Levels::DEBUG
142
- config.graylog = true
150
+ config.logger = <your GELF::Logger>
151
+ config.logger_method = :add
152
+ config.severity = GELF::Levels::DEBUG
153
+ config.graylog_formatter = FORMATTER
143
154
  end
144
155
  ```
145
156
 
146
- For more color options please refer to the [rainbow documentation](https://github.com/sickill/rainbow)
157
+ You also can use GELF Graylog format this way:
158
+
159
+ ```ruby
160
+ class Lograge::Formatters::Graylog2HttpLog < Lograge::Formatters::Graylog2
161
+ def short_message data
162
+ data[:response_body] = data[:response_body].to_s.byteslice(0, 32_766) unless data[:response_body].blank?
163
+ "[httplog] [#{data[:response_code]}] #{data[:method]} #{data[:url]}"
164
+ end
165
+ end
166
+
167
+ FORMATTER = Lograge::Formatters::Graylog2HttpLog.new
168
+ ```
169
+
170
+ Or define your own class that implements the `call` method
147
171
 
148
172
  ### Compact logging
149
173
 
@@ -5,7 +5,7 @@ module HttpLog
5
5
  attr_accessor :enabled,
6
6
  :compact_log,
7
7
  :json_log,
8
- :graylog,
8
+ :graylog_formatter,
9
9
  :logger,
10
10
  :logger_method,
11
11
  :severity,
@@ -31,7 +31,7 @@ module HttpLog
31
31
  @enabled = true
32
32
  @compact_log = false
33
33
  @json_log = false
34
- @graylog = false
34
+ @graylog_formatter = nil
35
35
  @logger = Logger.new($stdout)
36
36
  @logger_method = :log
37
37
  @severity = Logger::Severity::DEBUG
@@ -51,7 +51,7 @@ module HttpLog
51
51
  @prefix_response_lines = false
52
52
  @prefix_line_numbers = false
53
53
  @json_parser = JSON
54
- @filter_parameters = []
54
+ @filter_parameters = %w[password]
55
55
  end
56
56
  end
57
57
  end
@@ -32,7 +32,7 @@ module HttpLog
32
32
  parse_request(options)
33
33
  if config.json_log
34
34
  log_json(options)
35
- elsif config.graylog
35
+ elsif config.graylog_formatter
36
36
  log_graylog(options)
37
37
  elsif config.compact_log
38
38
  log_compact(options[:method], options[:url], options[:response_code], options[:benchmark])
@@ -207,8 +207,6 @@ module HttpLog
207
207
 
208
208
  def log_graylog(data)
209
209
  result = json_payload(data)
210
-
211
- result[:short_message] = result.delete(:url)
212
210
  begin
213
211
  send_to_graylog result
214
212
  rescue
@@ -219,7 +217,8 @@ module HttpLog
219
217
  end
220
218
 
221
219
  def send_to_graylog data
222
- config.logger.public_send(config.logger_method, config.severity, data)
220
+ data.compact!
221
+ config.logger.public_send(config.logger_method, config.severity, config.graylog_formatter.call(data))
223
222
  end
224
223
 
225
224
  def json_payload(data = {})
@@ -264,7 +263,8 @@ module HttpLog
264
263
  case msg
265
264
  when *string_classes
266
265
  config.filter_parameters.reduce(msg) do |m,key|
267
- m.to_s.gsub(/(#{key})=[^&]+/i, "#{key}=#{PARAM_MASK}")
266
+ scrubbed = m.to_s.encode('UTF-8', invalid: :replace, undef: :replace)
267
+ scrubbed.gsub(/(#{key})=[^&]+/i, "#{key}=#{PARAM_MASK}")
268
268
  end
269
269
  # ...and recurse over hashes
270
270
  when *hash_classes
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HttpLog
4
- VERSION = '1.4.2'.freeze
4
+ VERSION = '1.4.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.4.2
4
+ version: 1.4.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: 2020-02-09 00:00:00.000000000 Z
11
+ date: 2020-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ethon
@@ -274,7 +274,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
274
  - !ruby/object:Gem::Version
275
275
  version: '0'
276
276
  requirements: []
277
- rubygems_version: 3.1.2
277
+ rubygems_version: 3.0.3
278
278
  signing_key:
279
279
  specification_version: 4
280
280
  summary: Log outgoing HTTP requests.