l2meter 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/l2meter/emitter.rb +17 -16
- data/lib/l2meter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca246ee77800547afc00d19c21279922ed64a4d1
|
4
|
+
data.tar.gz: 6521d7dd5b8ded99ed1de5580681d800fdb67f3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656126158ebdc783c4a1d160bf2043bf6d93fe1653e04f13bdea8eac40a6c9366afae7f553a29c1aabbbc711a91a35e8ba25f21490d965b9eb8b746976592480
|
7
|
+
data.tar.gz: 6b388f5d352734326369b7c7d4ed4210d39f5da503c573a1b7f43976d2c00122acdc860ea0e4965790c688a42f9108bdb05abdc71394d95a28ada18008c4cd53
|
data/lib/l2meter/emitter.rb
CHANGED
@@ -8,16 +8,12 @@ module L2meter
|
|
8
8
|
@configuration = configuration
|
9
9
|
@buffer = {}
|
10
10
|
@autoflush = true
|
11
|
-
@start_times = []
|
12
11
|
@contexts = []
|
13
12
|
@outputs = []
|
14
13
|
end
|
15
14
|
|
16
15
|
def log(*args)
|
17
|
-
merge!
|
18
|
-
merge! *current_contexts
|
19
|
-
merge! *args
|
20
|
-
elapse!
|
16
|
+
merge! *current_contexts, *args
|
21
17
|
|
22
18
|
if block_given?
|
23
19
|
wrap &proc
|
@@ -26,11 +22,8 @@ module L2meter
|
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
29
|
-
def with_elapsed
|
30
|
-
|
31
|
-
yield
|
32
|
-
ensure
|
33
|
-
@start_times.pop
|
25
|
+
def with_elapsed(start_time = Time.now, &block)
|
26
|
+
context(elapsed_context(start_time), &block)
|
34
27
|
end
|
35
28
|
|
36
29
|
def with_output(output)
|
@@ -153,6 +146,8 @@ module L2meter
|
|
153
146
|
format_float(value)
|
154
147
|
when Time
|
155
148
|
value.iso8601
|
149
|
+
when Proc
|
150
|
+
format_value(value.call)
|
156
151
|
when Hash
|
157
152
|
format_value(value.inspect)
|
158
153
|
when Array
|
@@ -193,8 +188,7 @@ module L2meter
|
|
193
188
|
merge! params, at: :exception, exception: exception.class, message: exception.message
|
194
189
|
end
|
195
190
|
|
196
|
-
|
197
|
-
write
|
191
|
+
write elapsed_context(start_time)
|
198
192
|
|
199
193
|
raise exception if exception
|
200
194
|
|
@@ -202,16 +196,23 @@ module L2meter
|
|
202
196
|
end
|
203
197
|
|
204
198
|
def contexts_queue
|
205
|
-
[configuration.context, *@contexts].compact
|
199
|
+
[configuration.context, source_context, *@contexts].compact
|
206
200
|
end
|
207
201
|
|
208
202
|
def output_queue
|
209
203
|
[configuration.output, *@outputs].compact
|
210
204
|
end
|
211
205
|
|
212
|
-
def
|
213
|
-
|
214
|
-
|
206
|
+
def source_context
|
207
|
+
{ source: configuration.source }
|
208
|
+
end
|
209
|
+
|
210
|
+
def elapsed_context(since = Time.now)
|
211
|
+
{ elapsed: -> { elapsed_value(since) }}
|
212
|
+
end
|
213
|
+
|
214
|
+
def elapsed_value(since)
|
215
|
+
format_float(Time.now - since, unit: ?s)
|
215
216
|
end
|
216
217
|
end
|
217
218
|
end
|
data/lib/l2meter/version.rb
CHANGED