rack-access-capture 0.0.1 → 0.0.2
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2591634905f2a34e387fe164f308938081eb3fbd
|
4
|
+
data.tar.gz: dc5d14c4582419c3f9cd1e412ebef2114f6d84c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dae0a37fc4b9c41d56f534ccc142349352461e575c08df2a05ebec30e2be397097a947bfcff44d26efe282f39b319dc05397e2d78c404b37e0558befdc942591
|
7
|
+
data.tar.gz: a522106ef2ded0159dc89b366c60ff1fe671d75b24d37a687dbaa8a3c0d3de10d3c62b7854d9edb7d6d14adb4d51a12ec74516cbd5bc4e758979d8fda7ddf1c0
|
@@ -8,7 +8,15 @@ module Rack
|
|
8
8
|
|
9
9
|
class ConsoleAdapter < AbstractAdapter
|
10
10
|
|
11
|
-
|
11
|
+
JSON_FORMAT = "JSON".freeze
|
12
|
+
LTSV_FORMAT = "LTSV".freeze
|
13
|
+
|
14
|
+
private_constant :JSON_FORMAT, :LTSV_FORMAT
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
config = options || {}
|
18
|
+
@format = config["format"] || 'json'
|
19
|
+
@format.upcase!
|
12
20
|
end
|
13
21
|
|
14
22
|
def collect?(env)
|
@@ -16,8 +24,25 @@ module Rack
|
|
16
24
|
end
|
17
25
|
|
18
26
|
def collect(log)
|
27
|
+
case @format
|
28
|
+
when LTSV_FORMAT
|
29
|
+
ltsv(log)
|
30
|
+
when JSON_FORMAT
|
31
|
+
json(log)
|
32
|
+
else
|
33
|
+
json(log)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def json(log)
|
19
40
|
$stdout.puts log.to_json
|
20
41
|
end
|
42
|
+
|
43
|
+
def ltsv(log)
|
44
|
+
$stdout.puts log.map { |k, v| "#{k}:#{v}" }.join("\t") + "\n"
|
45
|
+
end
|
21
46
|
end
|
22
47
|
end
|
23
48
|
end
|
@@ -15,11 +15,16 @@ module Rack
|
|
15
15
|
|
16
16
|
def call(env)
|
17
17
|
captured_request = @config._watcher.nil? ? {} : @config._watcher.request_capture(env)
|
18
|
+
began_at = Time.now.instance_eval { to_i + (usec / 1000000.0) }
|
19
|
+
|
18
20
|
status_code, header, body = @app.call(env)
|
21
|
+
ensure
|
22
|
+
exec_time = Time.now.instance_eval { to_i + (usec / 1000000.0) } - began_at
|
19
23
|
captured_response = @config._watcher.nil? ? {} : @config._watcher.response_capture(env, status_code, header)
|
20
24
|
|
21
25
|
if !@config._collector.nil? && @config._collector.collect?(env)
|
22
26
|
access_log = @config._internal_watcher.access_log(env, status_code, header)
|
27
|
+
access_log["app_exec_time"] = exec_time
|
23
28
|
captured_access_log = merge_logs(captured_request, captured_response, access_log)
|
24
29
|
@config._collector.collect(captured_access_log)
|
25
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-access-capture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- moonstruckdrops
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: woothee
|