log_spy 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +4 -0
- data/lib/log_spy/payload.rb +4 -0
- data/lib/log_spy/spy.rb +10 -5
- data/lib/log_spy/version.rb +1 -1
- data/spec/payload_spec.rb +25 -0
- data/spec/spy_spec.rb +1 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2dc87b4c4a64a5e9cca30f4274c31b5410b7658
|
4
|
+
data.tar.gz: dd24f18962e75a3efc5c029a9445593e3d7b693e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fffa272cda3094c4c41763040ca61adf3b117628b4cb7be8f399046771a8869bc7e7de0ad8732c6a2f57a52a84d09e64210fec7dce8d9fa02fd163705deb83d
|
7
|
+
data.tar.gz: fc708c4642da96e831e8bf4f09ea661e5b5b4d20b25d8c896144aab8031a99e0bb6ddaf4a674760b280b0bd8b84ba886312b92d7051bd787cd8375bb1a6ea2fa
|
data/History.md
CHANGED
data/lib/log_spy/payload.rb
CHANGED
@@ -26,6 +26,10 @@ class LogSpy::Payload
|
|
26
26
|
hash[:error] = { :message => @error.message, :backtrace => @error.backtrace }
|
27
27
|
end
|
28
28
|
|
29
|
+
if controller_params = @req.env['action_dispatch.request.parameters']
|
30
|
+
hash[:controller_action] = "#{controller_params['controller']}##{controller_params['action']}"
|
31
|
+
end
|
32
|
+
|
29
33
|
hash.to_json
|
30
34
|
end
|
31
35
|
|
data/lib/log_spy/spy.rb
CHANGED
@@ -13,18 +13,23 @@ class LogSpy::Spy
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def call env
|
16
|
+
@env = env
|
16
17
|
@start_time = Time.now.to_f
|
17
|
-
@
|
18
|
-
@status, @header, @body = @app.call(env)
|
18
|
+
@status, header, body = @app.call(env)
|
19
19
|
|
20
20
|
@sqs_thread = send_sqs_async
|
21
|
-
|
21
|
+
|
22
|
+
[ @status, header, body ]
|
22
23
|
rescue Exception => err
|
23
24
|
@sqs_thread = send_sqs_async(err)
|
24
|
-
|
25
25
|
raise err
|
26
26
|
end
|
27
27
|
|
28
|
+
def req
|
29
|
+
Rack::Request.new @env
|
30
|
+
end
|
31
|
+
private :req
|
32
|
+
|
28
33
|
def send_sqs_async(err = nil)
|
29
34
|
@sqs_thread = Thread.new do
|
30
35
|
status = err ? 500 : @status
|
@@ -34,7 +39,7 @@ class LogSpy::Spy
|
|
34
39
|
:duration => duration,
|
35
40
|
:status => status
|
36
41
|
})
|
37
|
-
payload = ::LogSpy::Payload.new(
|
42
|
+
payload = ::LogSpy::Payload.new(req, res, @start_time.to_i, err)
|
38
43
|
|
39
44
|
sqs.queues[@sqs_url].send_message(payload.to_json)
|
40
45
|
end
|
data/lib/log_spy/version.rb
CHANGED
data/spec/payload_spec.rb
CHANGED
@@ -18,6 +18,7 @@ describe LogSpy::Payload do
|
|
18
18
|
:request_method => request_method,
|
19
19
|
:ip => ip,
|
20
20
|
:query_string => query_string,
|
21
|
+
:env => {},
|
21
22
|
:body => body)
|
22
23
|
end
|
23
24
|
|
@@ -79,11 +80,31 @@ describe LogSpy::Payload do
|
|
79
80
|
allow(request).to receive_messages(:env => { 'RAW_POST_BODY' => 'raw-post-body' })
|
80
81
|
expected_hash[:request][:body] = 'raw-post-body'
|
81
82
|
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
shared_examples "if env['action_dispatch.request.parameters']" do
|
87
|
+
before :each do
|
88
|
+
controller_params = { 'controller' => 'users', 'action' => 'show' }
|
89
|
+
env = { 'action_dispatch.request.parameters' => controller_params }
|
90
|
+
allow(request).to receive_messages(:env => env)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'returns hash with `controller_action`' do
|
94
|
+
expected_hash[:controller_action] = "users#show"
|
95
|
+
expected_hash[:request][:body] = nil
|
96
|
+
|
97
|
+
expect(payload.to_json).to eq(expected_hash.to_json)
|
98
|
+
end
|
82
99
|
end
|
83
100
|
|
84
101
|
context "if request ends without error" do
|
85
102
|
let(:payload) { LogSpy::Payload.new request, response, begin_at }
|
86
103
|
|
104
|
+
context "if env['action_dispatch.request.parameters']" do
|
105
|
+
include_examples "if env['action_dispatch.request.parameters']"
|
106
|
+
end
|
107
|
+
|
87
108
|
context "if body can be read" do
|
88
109
|
include_context "if_body_readable"
|
89
110
|
include_examples 'ensure_payload_formats'
|
@@ -105,6 +126,10 @@ describe LogSpy::Payload do
|
|
105
126
|
}
|
106
127
|
end
|
107
128
|
|
129
|
+
context "if env['action_dispatch.request.parameters']" do
|
130
|
+
include_examples "if env['action_dispatch.request.parameters']"
|
131
|
+
end
|
132
|
+
|
108
133
|
context "if request body can be read" do
|
109
134
|
include_context 'if_body_readable'
|
110
135
|
include_examples 'ensure_payload_formats'
|
data/spec/spy_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_spy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yang-Hsing Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.2.2
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: send rack application log to Amazon SQS
|