rack-traffic-logger 0.2.6 → 0.2.7
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e2d9d6dbf7e643b44c6a027b40d72ae965905b6
|
4
|
+
data.tar.gz: 0720be927009f204912e451fe1806efe77f75211
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6b621b06f98cecb5b0caa50a03d3c24050981a75d95bf3d19a40e248aafae45b27284b997ded3942404207d3f68dd556d68af832985e3a556387680edeb1378
|
7
|
+
data.tar.gz: 081fe2c8212c2db6c80ef2967f2013e1b183e91962cd33b84602566884b75cb88cbf8ee10516e3fd533326eeb4ce495d8f773d0d5fcf802ae6f9162b7bd184d2
|
@@ -1,5 +1,11 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
require 'rack/body_proxy'
|
3
|
+
require 'zlib'
|
4
|
+
require 'securerandom'
|
5
|
+
|
1
6
|
module Rack
|
2
7
|
class TrafficLogger
|
8
|
+
# noinspection RubyStringKeysInHashInspection
|
3
9
|
class Request
|
4
10
|
|
5
11
|
def initialize(logger)
|
@@ -62,7 +68,7 @@ module Rack
|
|
62
68
|
def get_real_body(body)
|
63
69
|
|
64
70
|
# For bodies representing temporary files
|
65
|
-
body = File.open(body.path, 'rb') { |f| f.read } if body.respond_to? :path
|
71
|
+
body = ::File.open(body.path, 'rb') { |f| f.read } if body.respond_to? :path
|
66
72
|
|
67
73
|
# For bodies representing streams
|
68
74
|
body = body.read.tap { body.rewind } if body.respond_to? :read
|
@@ -89,16 +95,23 @@ module Rack
|
|
89
95
|
end
|
90
96
|
|
91
97
|
def log(event)
|
92
|
-
# noinspection RubyStringKeysInHashInspection
|
93
98
|
hash = {
|
94
99
|
'timestamp' => Time.now.strftime('%FT%T.%3N%:z'),
|
95
100
|
'request_log_id' => @id,
|
96
101
|
'event' => event
|
97
102
|
}
|
98
|
-
yield hash rescue hash.merge!
|
103
|
+
yield hash rescue hash.merge! 'logger_exception' => expand_exception($!)
|
99
104
|
@logger.log hash
|
100
105
|
end
|
101
106
|
|
107
|
+
def expand_exception(e)
|
108
|
+
{
|
109
|
+
'class' => e.class.name,
|
110
|
+
'message' => e.message,
|
111
|
+
'backtrace' => e.backtrace
|
112
|
+
}
|
113
|
+
end
|
114
|
+
|
102
115
|
end
|
103
116
|
end
|
104
117
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Rack
|
2
4
|
class TrafficLogger
|
3
5
|
class StreamSimulator
|
@@ -11,7 +13,9 @@ module Rack
|
|
11
13
|
case input['event']
|
12
14
|
when 'request' then format_request input
|
13
15
|
when 'response' then format_response input
|
14
|
-
else
|
16
|
+
else ''
|
17
|
+
end.tap do |result|
|
18
|
+
result << format_exception(input['logger_exception']) if input.key? 'logger_exception'
|
15
19
|
end
|
16
20
|
end
|
17
21
|
|
@@ -57,6 +61,10 @@ module Rack
|
|
57
61
|
result << format_body(input, headers && headers['Content-Type'])
|
58
62
|
end
|
59
63
|
|
64
|
+
def format_exception(e)
|
65
|
+
"\n\n#{e['class']}: #{e['message']}\n #{e['backtrace'].join "\n "}"
|
66
|
+
end
|
67
|
+
|
60
68
|
def render(template, data)
|
61
69
|
template.gsub(/:(\w+)/) { data[$1.to_sym] }
|
62
70
|
end
|
data/lib/rack/traffic_logger.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-traffic-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil E. Pearson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|