clogger 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/GIT-VERSION-GEN +1 -1
- data/lib/clogger/pure.rb +19 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd4966f902d26e1a0037ddf465336678a0d342ed
|
4
|
+
data.tar.gz: b2f531772d210d2823187a8de8c76a1f8cdf0387
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa24a2c1f213548c32055f04bbeb1e113ec063d27f77fb264ae121cb865aba887f525366a52cc375731be2f121a5dc102053b1ee146deb3c21e2f33ba5d209e0
|
7
|
+
data.tar.gz: 618537067d02ef74554bc5355b0364c5bb4260212ee7b6cca218fe74a683cfed4e88ce3d0c257d9d45e14a1826044368c373c34e79e977c73a67f3fbf2d867ce
|
data/GIT-VERSION-GEN
CHANGED
data/lib/clogger/pure.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
class Clogger
|
7
7
|
|
8
8
|
attr_accessor :env, :status, :headers, :body
|
9
|
-
attr_writer :body_bytes_sent
|
9
|
+
attr_writer :body_bytes_sent, :start
|
10
10
|
|
11
11
|
def initialize(app, opts = {})
|
12
12
|
# trigger autoload to avoid thread-safety issues later on
|
@@ -28,10 +28,10 @@ class Clogger
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def call(env)
|
31
|
-
|
31
|
+
start = mono_now
|
32
32
|
resp = @app.call(env)
|
33
33
|
unless resp.instance_of?(Array) && resp.size == 3
|
34
|
-
log(env, 500, {})
|
34
|
+
log(env, 500, {}, start)
|
35
35
|
raise TypeError, "app response not a 3 element Array: #{resp.inspect}"
|
36
36
|
end
|
37
37
|
status, headers, body = resp
|
@@ -39,13 +39,14 @@ class Clogger
|
|
39
39
|
if @wrap_body
|
40
40
|
@reentrant = env['rack.multithread'] if @reentrant.nil?
|
41
41
|
wbody = @reentrant ? self.dup : self
|
42
|
+
wbody.start = start
|
42
43
|
wbody.env = env
|
43
44
|
wbody.status = status
|
44
45
|
wbody.headers = headers
|
45
46
|
wbody.body = body
|
46
47
|
return [ status, headers, wbody ]
|
47
48
|
end
|
48
|
-
log(env, status, headers)
|
49
|
+
log(env, status, headers, start)
|
49
50
|
[ status, headers, body ]
|
50
51
|
end
|
51
52
|
|
@@ -60,8 +61,8 @@ class Clogger
|
|
60
61
|
|
61
62
|
def close
|
62
63
|
@body.close if @body.respond_to?(:close)
|
63
|
-
|
64
|
-
|
64
|
+
ensure
|
65
|
+
log(@env, @status, @headers)
|
65
66
|
end
|
66
67
|
|
67
68
|
def reentrant?
|
@@ -153,7 +154,7 @@ private
|
|
153
154
|
format % [ sec, usec / div ]
|
154
155
|
end
|
155
156
|
|
156
|
-
def log(env, status, headers)
|
157
|
+
def log(env, status, headers, start = @start)
|
157
158
|
str = @fmt_ops.map { |op|
|
158
159
|
case op[0]
|
159
160
|
when OP_LITERAL; op[1]
|
@@ -164,7 +165,7 @@ private
|
|
164
165
|
when OP_TIME_LOCAL; Time.now.strftime(op[1])
|
165
166
|
when OP_TIME_UTC; Time.now.utc.strftime(op[1])
|
166
167
|
when OP_REQUEST_TIME
|
167
|
-
t =
|
168
|
+
t = mono_now - start
|
168
169
|
time_format(t.to_i, (t - t.to_i) * 1000000, op[1], op[2])
|
169
170
|
when OP_TIME
|
170
171
|
t = Time.now
|
@@ -184,4 +185,14 @@ private
|
|
184
185
|
end
|
185
186
|
nil
|
186
187
|
end
|
188
|
+
|
189
|
+
# favor monotonic clock if possible, and try to use clock_gettime in
|
190
|
+
# more recent Rubies since it generates less garbage
|
191
|
+
if defined?(Process::CLOCK_MONOTONIC)
|
192
|
+
def mono_now; Process.clock_gettime(Process::CLOCK_MONOTONIC); end
|
193
|
+
elsif defined?(Process::CLOCK_REALTIME)
|
194
|
+
def mono_now; Process.clock_gettime(Process::CLOCK_REALTIME); end
|
195
|
+
else
|
196
|
+
def mono_now; Time.now.to_f; end
|
197
|
+
end
|
187
198
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clogger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cloggers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|