yog 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 7a368faf2b40b6f7874d643db6cdf6d92f888f11d11e6d9592564f99e9f347c8
4
- data.tar.gz: 9326d66736f140ab0ca623efb54596e3dd90dba49e7256107a10679b83f8436c
3
+ metadata.gz: 75d9f8013927b9e382cb7b01d4007167d0ade47f1a018f3be60e2042530e29f1
4
+ data.tar.gz: 5a02f9b446a8b614bd406afbdfd4fedadbd3214fabacce26eb9861e0a71b2609
5
5
  SHA512:
6
- metadata.gz: 7a76c80aeabb756397ec4aa6a5311dee0d781590a4fbcff68177f7b580bf02d5c8b9118cb288e65005208a2b801beb121319b4b0f077b8152a1386a85fa7757b
7
- data.tar.gz: fcb89cc14d962bed269ac576503861a99e82c61c0da22ea34415199210310139bc05e01438f1a9c44229b47db2eecf115245ac76aa0da6630d4179e7060a96fa
6
+ metadata.gz: dff04a9a278360f3b82b8cfa21f90469fc0401d59373e193ebf5b021d342ff017044973578df2e5978e760b1b7a6e01b936ff190ef9b4644513b7ae42693ed42
7
+ data.tar.gz: b2b11557f4b030a64a722ef966b9bfcad0d2924058ae0c555358b673ed7843965950d4f9689775e0184f5e37448601253000a3b5008d06d77912f0ba35f44068
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yog (0.0.0)
4
+ yog (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/yog.rb CHANGED
@@ -16,24 +16,30 @@ class Yog
16
16
 
17
17
  # Log a message. Logs any given block's duration as `elapsed=float` ms.
18
18
  def write(msg, **fields)
19
+ if @output.nil?
20
+ return block_given? && yield
21
+ end
22
+
19
23
  if msg.is_a?(Hash)
20
- fields, msg = msg, nil
24
+ msg, fields = nil, fields.merge(msg)
21
25
  end
22
26
 
23
- result = if block_given?
24
- start = Time.now
27
+ start = Time.now.utc
28
+ prefix = { now: start }
29
+ result = nil
25
30
 
26
- yield.tap do
27
- fields[:duration] = (Time.now - start) * 1000
28
- end
31
+ if msg
32
+ prefix[:msg] = msg
29
33
  end
30
34
 
31
- unless @output.nil?
32
- prefix = { now: Time.now.utc, msg: msg }
33
- combined = Yog.merge(prefix, fields, @context)
34
- @output.puts(@generator.generate(combined))
35
+ if block_given?
36
+ result = yield
37
+ prefix[:duration] = (Time.now - start) * 1000
35
38
  end
36
39
 
40
+ combined = Yog.merge(prefix, fields, @context)
41
+ @output.puts(@generator.generate(combined))
42
+
37
43
  result
38
44
  end
39
45
 
@@ -6,7 +6,7 @@ class Yog
6
6
 
7
7
  # https://brandur.org/logfmt
8
8
  module Logfmt
9
- def self.generate(**fields)
9
+ def self.generate(fields)
10
10
  fields.map { |k, v| "#{k}=#{render(v)}" }.join(" ")
11
11
  end
12
12
 
@@ -14,12 +14,18 @@ class Yog
14
14
 
15
15
  def self.render(v)
16
16
  case v
17
+ when NilClass
18
+ "nil"
19
+ when TrueClass
20
+ "true"
21
+ when FalseClass
22
+ "false"
17
23
  when DateTime, Time
18
24
  v.iso8601(2)
19
25
  when Float
20
26
  sprintf("%.2f", v)
21
- when NilClass
22
- "nil"
27
+ when Numeric
28
+ v.to_s
23
29
  when String
24
30
  (/[ '",{}\[\]:=]/ =~ v) ? v.inspect : v
25
31
  else
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "yog"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["John Barnette"]
5
5
  spec.email = ["john@jbarnette.com"]
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Barnette
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-15 00:00:00.000000000 Z
11
+ date: 2018-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler