rack-traffic-logger 0.2.3 → 0.2.4

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: 046f870b9d6d0d7ad599d9be02eeab36373e32b6
4
- data.tar.gz: ed3d557fd8e5c8f3b7a4293afdfc63d8380dc73b
3
+ metadata.gz: 14b29cb8230446091b0ff4d48a732e4cb907381c
4
+ data.tar.gz: 28bf54115618158d68942804a366894a3cc59537
5
5
  SHA512:
6
- metadata.gz: 4d930ba34abf2ca3d9c6d8abe774b1c9efede75417cf0053de75c144281eed2c0525a9ce856892d70588bf9ed2b3487cd3f7569465c1cc1019c14c2ba426475d
7
- data.tar.gz: a725b479cc1d70dad8d343a01a5c8eb9055ecc9b7ace87cff123f450043ae1dd7f4aeecfa64dd6794a2a99e7b5ea4462218b756c7a31b6897a49d0c9a8153fee
6
+ metadata.gz: f3deff06a541bab57142e46c2f11a077c4dc9ea662e11585f7f4df00836a8d50a45a65f4d9317c93afca930382ef694be3fa56404553f70079d39b455763ede1
7
+ data.tar.gz: 71d3bebc92b6b9e4587a25826f18813feb76a901e1c990b3b578dd06945137d5c2e71a632f994882a09fe6b32a8e25a89a56820f531461f881d8050b09de6116
data/README.md CHANGED
@@ -153,6 +153,39 @@ It's ruby, plus these rules:
153
153
  - Use `a` for `all`, `h` for `headers`, `b` for `bodies`, `ih` for `request_headers`, `ib` for `request_bodies`, `oh` for `response_headers`, and `ob` for `response_bodies` (think of `i` for *input*, and `o` for *output*).
154
154
  - Use `o` for `only` and `f` for false.
155
155
 
156
+ ### Express Setup
157
+
158
+ If you're reading log config from an environment variable, use express setup in place of `use` in a rack-up file to conditionally set up logging on your stack.
159
+
160
+ ```ruby
161
+ # config.ru
162
+ Rack::TrafficLogger.use on: self
163
+ ```
164
+
165
+ Or, with some configuration:
166
+
167
+ ```ruby
168
+ # config.ru
169
+ Rack::TrafficLogger.use on: self,
170
+ filter: ENV['LOG_INBOUND_HTTP'],
171
+ formatter: Rack::TrafficLogger::Formatter::JSON.new,
172
+ log_path: ::File.expand_path('../log/http_in.log', __FILE__)
173
+
174
+ ```
175
+
176
+ - Express setup will send `use` to the object passed to the `on:` argument. In a rack-up file, pass `self`.
177
+ - Logging will not be set up if `filter` is one of: `0 no false none off nil`, or a blank string.
178
+ - Logging will revert to basic logging (no headers or bodies) if `filter` is one of `1 yes true normal basic minimal on`.
179
+ - Omit `filter` to use default (basic) log filtering.
180
+ - Omit `formatter` to use default (stream-like) log formatting.
181
+ - Omit `log_path` to write directly to standard output (via `/dev/stdout`).
182
+
183
+ Under typical conditions, express setup internally calls:
184
+
185
+ ```ruby
186
+ on.use Rack::TrafficLogger, log_path, formatter, format
187
+ ```
188
+
156
189
  ### Tailing a JSON log
157
190
 
158
191
  Tailing a JSON log can induce migraines. There are a couple of solutions:
@@ -0,0 +1,19 @@
1
+ module Rack
2
+ class TrafficLogger
3
+
4
+ def self.use(on: nil, filter: '', log_path: '/dev/stdout', formatter: nil)
5
+ filter = (filter || '').to_s.downcase.strip
6
+ unless ['0', 'no', 'false', 'nil', 'none', '', 'off'].include? filter
7
+ args = [Rack::TrafficLogger, log_path]
8
+ args << formatter if formatter
9
+ begin
10
+ raise if %w[1 yes true normal basic minimal on].include? filter
11
+ on.use *args, filter
12
+ rescue
13
+ on.use *args
14
+ end
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class TrafficLogger
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
  end
5
5
  end
@@ -4,6 +4,7 @@ require_relative 'traffic_logger/option_interpreter'
4
4
  require_relative 'traffic_logger/stream_simulator'
5
5
  require_relative 'traffic_logger/formatter'
6
6
  require_relative 'traffic_logger/reader'
7
+ require_relative 'traffic_logger/express_setup'
7
8
 
8
9
  require 'json'
9
10
  require 'securerandom'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-traffic-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil E. Pearson
@@ -37,6 +37,7 @@ files:
37
37
  - bin/parse-rack-traffic-log
38
38
  - lib/rack/traffic_logger.rb
39
39
  - lib/rack/traffic_logger/echo.rb
40
+ - lib/rack/traffic_logger/express_setup.rb
40
41
  - lib/rack/traffic_logger/formatter.rb
41
42
  - lib/rack/traffic_logger/formatter/json.rb
42
43
  - lib/rack/traffic_logger/formatter/stream.rb