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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/yog.rb +16 -10
- data/lib/yog/logfmt.rb +9 -3
- data/yog.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75d9f8013927b9e382cb7b01d4007167d0ade47f1a018f3be60e2042530e29f1
|
4
|
+
data.tar.gz: 5a02f9b446a8b614bd406afbdfd4fedadbd3214fabacce26eb9861e0a71b2609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dff04a9a278360f3b82b8cfa21f90469fc0401d59373e193ebf5b021d342ff017044973578df2e5978e760b1b7a6e01b936ff190ef9b4644513b7ae42693ed42
|
7
|
+
data.tar.gz: b2b11557f4b030a64a722ef966b9bfcad0d2924058ae0c555358b673ed7843965950d4f9689775e0184f5e37448601253000a3b5008d06d77912f0ba35f44068
|
data/Gemfile.lock
CHANGED
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
|
-
|
24
|
+
msg, fields = nil, fields.merge(msg)
|
21
25
|
end
|
22
26
|
|
23
|
-
|
24
|
-
|
27
|
+
start = Time.now.utc
|
28
|
+
prefix = { now: start }
|
29
|
+
result = nil
|
25
30
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
31
|
+
if msg
|
32
|
+
prefix[:msg] = msg
|
29
33
|
end
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
|
data/lib/yog/logfmt.rb
CHANGED
@@ -6,7 +6,7 @@ class Yog
|
|
6
6
|
|
7
7
|
# https://brandur.org/logfmt
|
8
8
|
module Logfmt
|
9
|
-
def self.generate(
|
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
|
22
|
-
|
27
|
+
when Numeric
|
28
|
+
v.to_s
|
23
29
|
when String
|
24
30
|
(/[ '",{}\[\]:=]/ =~ v) ? v.inspect : v
|
25
31
|
else
|
data/yog.gemspec
CHANGED
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.
|
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-
|
11
|
+
date: 2018-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|