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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f4adb53ff781efc36f715a3cace441b9020719f
4
- data.tar.gz: fd0e1932d11244637a20f3d63430ea176cf69441
3
+ metadata.gz: ca246ee77800547afc00d19c21279922ed64a4d1
4
+ data.tar.gz: 6521d7dd5b8ded99ed1de5580681d800fdb67f3f
5
5
  SHA512:
6
- metadata.gz: 8aeeb27f3afa5ddcb71db8dce17ee624e339cae4fccc7ba064cbdf65372e51609da4849e93d575297332e40851d11d618d0c40266ba2ac198cf485bfb07b8033
7
- data.tar.gz: 8a8a6555a573d7743f2a94939c1a7e8b51cbff0c226e8fb9de3f1f660dc748857ed32e4d18fc901545764a99223d59b074520661744fdea23d4a31fe7ba4cea1
6
+ metadata.gz: 656126158ebdc783c4a1d160bf2043bf6d93fe1653e04f13bdea8eac40a6c9366afae7f553a29c1aabbbc711a91a35e8ba25f21490d965b9eb8b746976592480
7
+ data.tar.gz: 6b388f5d352734326369b7c7d4ed4210d39f5da503c573a1b7f43976d2c00122acdc860ea0e4965790c688a42f9108bdb05abdc71394d95a28ada18008c4cd53
@@ -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! source: configuration.source
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
- @start_times << Time.now
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
- elapse! start_time
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 elapse!(since = @start_times.last)
213
- return unless since
214
- merge! elapsed: format_float(Time.now - since, unit: ?s)
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
@@ -1,3 +1,3 @@
1
1
  module L2meter
2
- VERSION = "0.8.0".freeze
2
+ VERSION = "0.9.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: l2meter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pravosud