ltsv_ng 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ltsv_ng/formatter.rb +11 -4
- data/lib/ltsv_ng/version.rb +1 -1
- data/ltsv_ng.gemspec +1 -0
- data/spec/formatter_spec.rb +7 -0
- data/spec/logger_spec.rb +8 -4
- data/spec/spec_helper.rb +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14be5c2fcdc34c05f693a36209a81f6cf36baff8
|
4
|
+
data.tar.gz: 441f8accb004f00caf648b59236987535ba275c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ee67bf03c5addaf509087c566c9416aa7c9dca9fcec91008c756a8442bb928385d223a9053f3f3041c6fdcdb8da20c81c70398c1307fa2a06fcd31a04d21935
|
7
|
+
data.tar.gz: 66f47c99844e5a16b3ce7c632100c26c92154898efa02c8a29aa9cffc860a96ba8d58054450ab6ad39d8ed3b3bc7139127c81223e34b890d61b2b8421a9f12e5
|
data/lib/ltsv_ng/formatter.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
module LtsvNg
|
2
2
|
class Formatter < ::Logger::Formatter
|
3
3
|
def call(severity, timestamp, progname, msg)
|
4
|
-
raws =
|
4
|
+
raws = { level: severity, time: timestamp, uuid: SecureRandom.uuid }
|
5
5
|
case msg
|
6
6
|
when Hash
|
7
|
-
|
7
|
+
msg.each do |key, value|
|
8
|
+
if raws.has_key? key
|
9
|
+
raws["dup_#{key}".to_sym] = value
|
10
|
+
else
|
11
|
+
raws[key] = value
|
12
|
+
end
|
13
|
+
end
|
8
14
|
when String
|
9
|
-
raws
|
15
|
+
raws[:msg] = msg
|
10
16
|
end
|
11
|
-
|
17
|
+
|
18
|
+
raws.inject(Array.new) { |h, (key, value)| h << "#{key}:#{value}" }.join("\t") + "\n"
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
data/lib/ltsv_ng/version.rb
CHANGED
data/ltsv_ng.gemspec
CHANGED
data/spec/formatter_spec.rb
CHANGED
@@ -20,5 +20,12 @@ describe "LtsvNg::Formatter" do
|
|
20
20
|
expect(text).to eq "level:INFO\ttime:#{time}\tuuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745\tid:123\tname:foobar\n"
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
context "Duplicate default hash key " do
|
25
|
+
it "returns changed key text" do
|
26
|
+
text = formatter.call("INFO", time, nil, { id: 123, name: "foobar", time: 456})
|
27
|
+
expect(text).to eq "level:INFO\ttime:#{time}\tuuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745\tid:123\tname:foobar\tdup_time:456\n"
|
28
|
+
end
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
data/spec/logger_spec.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
require_relative "spec_helper"
|
2
2
|
|
3
3
|
describe "LtsvNg::Logger" do
|
4
|
-
|
4
|
+
|
5
5
|
before do
|
6
6
|
@output = StringIO.new
|
7
7
|
@logger = LtsvNg::Logger.new(@output)
|
8
8
|
allow(SecureRandom).to receive(:uuid).and_return("b746d58e-e4c0-4f2b-86fd-f8ff78131745")
|
9
|
+
Timecop.freeze
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
Timecop.return
|
9
14
|
end
|
10
15
|
|
11
16
|
describe "#formatter" do
|
@@ -17,11 +22,10 @@ describe "LtsvNg::Logger" do
|
|
17
22
|
describe "#info" do
|
18
23
|
it "returns info log by String Text" do
|
19
24
|
@logger.info("Test")
|
20
|
-
|
21
25
|
@output.seek(0)
|
22
26
|
ltsv = @output.read.strip.split("\t")
|
23
27
|
expect(ltsv).to include("level:INFO")
|
24
|
-
expect(ltsv).to include("time:#{
|
28
|
+
expect(ltsv).to include("time:#{Time.now}")
|
25
29
|
expect(ltsv).to include("uuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745")
|
26
30
|
expect(ltsv).to include("msg:Test")
|
27
31
|
end
|
@@ -31,7 +35,7 @@ describe "LtsvNg::Logger" do
|
|
31
35
|
@output.seek(0)
|
32
36
|
ltsv = @output.read.strip.split("\t")
|
33
37
|
expect(ltsv).to include("level:INFO")
|
34
|
-
expect(ltsv).to include("time:#{
|
38
|
+
expect(ltsv).to include("time:#{Time.now}")
|
35
39
|
expect(ltsv).to include("id:123")
|
36
40
|
expect(ltsv).to include("uuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745")
|
37
41
|
expect(ltsv).to include("name:foobar")
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ltsv_ng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirocaster
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: timecop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: LTSV logger for Ruby application.
|
56
70
|
email:
|
57
71
|
- hohtsuka@gmail.com
|