simple-rack-logger 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
data/lib/simple-rack-logger.rb
CHANGED
@@ -8,14 +8,24 @@ module Rack
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
+
|
12
|
+
uuid = unique_identy
|
13
|
+
|
11
14
|
request = Rack::Request.new(env)
|
12
15
|
block = @filters.select { |filter| filter.respond_to?(:filter) && filter.send(:filter, request) }
|
13
16
|
if block.empty?
|
14
|
-
logger.info(expose(request, env))
|
17
|
+
logger.info("IDENT:|#{uuid}| REQUEST_VALUE:|#{expose(request, env)}|")
|
18
|
+
logger.flush
|
19
|
+
end
|
20
|
+
|
21
|
+
return_value = @app.call(env)
|
22
|
+
|
23
|
+
if block.empty?
|
24
|
+
logger.info("IDENT:|#{uuid}| RETURN_VALUE:|#{expose_return(return_value).to_s}|")
|
15
25
|
logger.flush
|
16
26
|
end
|
17
27
|
|
18
|
-
|
28
|
+
return_value
|
19
29
|
end
|
20
30
|
|
21
31
|
private
|
@@ -26,10 +36,22 @@ module Rack
|
|
26
36
|
show << "[params: #{params.join('; ')}]" unless params.empty?
|
27
37
|
|
28
38
|
headers = env.select { |key, value| key.start_with?('HTTP_') }
|
29
|
-
show << " [
|
39
|
+
show << " [headers: #{headers.collect { |pair| pair.join("=") }}" unless headers.empty?
|
30
40
|
|
31
41
|
show
|
32
42
|
end
|
33
43
|
|
44
|
+
def expose_return(return_value)
|
45
|
+
return_value = [return_value] unless return_value.is_a? Array
|
46
|
+
|
47
|
+
return_value.map do |item|
|
48
|
+
(item.is_a? Rack::BodyProxy) ? item.send(:body) : item.to_s
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def unique_identy
|
53
|
+
UUID.new.generate
|
54
|
+
end
|
34
55
|
end
|
35
56
|
end
|
57
|
+
|
data/simple-rack-logger.gemspec
CHANGED
@@ -17,6 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
+
gem.add_dependency 'uuid'
|
21
|
+
|
20
22
|
gem.add_development_dependency 'simplecov'
|
21
23
|
gem.add_development_dependency 'rspec'
|
22
24
|
gem.add_development_dependency 'guard-rspec'
|
@@ -41,8 +41,13 @@ describe Rack::RequestLogger do
|
|
41
41
|
}
|
42
42
|
|
43
43
|
it 'log request information from env' do
|
44
|
-
|
45
|
-
|
44
|
+
|
45
|
+
subject.should_receive(:unique_identy).and_return('1234')
|
46
|
+
|
47
|
+
app.should_receive(:call).and_return("Something")
|
48
|
+
logger.should_receive(:info).with('IDENT:|1234| REQUEST_VALUE:|GET: http://localhost:9393/v1/crachas.xml for 127.0.0.1 [headers: ["HTTP_USER_AGENT=curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3", "HTTP_HOST=localhost:9393", "HTTP_ACCEPT=*/*", "HTTP_VERSION=HTTP/1.1"]|')
|
49
|
+
logger.should_receive(:info).with('IDENT:|1234| RETURN_VALUE:|["Something"]|')
|
50
|
+
|
46
51
|
subject.call(env)
|
47
52
|
end
|
48
53
|
end
|
@@ -63,5 +68,4 @@ describe Rack::RequestLogger do
|
|
63
68
|
end
|
64
69
|
|
65
70
|
end
|
66
|
-
|
67
71
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-rack-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: uuid
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: simplecov
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|