ltsv_ng 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/ltsv_ng/formatter.rb +1 -1
- data/lib/ltsv_ng/version.rb +1 -1
- data/lib/ltsv_ng.rb +1 -0
- data/spec/formatter_spec.rb +4 -2
- data/spec/logger_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 410eb98ad781584ffb894d45d3bbc912c836c54c
|
4
|
+
data.tar.gz: 8d07103d322bde19bb36d32b79ca26631563d5bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e812debf57093ea7ca9395f0748694d7cbeb304eea92d486a11c6e12731124cab4b5cd8c80f326601cebe9b92f4d7f54309da7c2a4e022a330bd73ccc46e577
|
7
|
+
data.tar.gz: b0db9b99a5f9a646687839ad01cc0a6e05e6cca46843589acec10b63e229ad340b53b02a88d950a78f7dae968a59726da28afc473407e13f4a5fa1979a4070cf
|
data/README.md
CHANGED
@@ -40,8 +40,10 @@ end
|
|
40
40
|
### Sample log
|
41
41
|
|
42
42
|
```ruby
|
43
|
-
Rails.logger.info "foobar" # => level:INFO
|
44
|
-
|
43
|
+
Rails.logger.info "foobar" # => level:INFO time:2015-08-05 12:55:25 +0900 uuid:958125fc-4f35-4f45-9eef-046fece2dfc2 msg:foobar
|
44
|
+
|
45
|
+
|
46
|
+
Rails.logger.info id: 123, name: "alice" # => level:INFO time:2015-08-05 12:56:03 +0900 uuid:26bd133e-94b2-450d-9ad5-1855c7649ccd id:123 name:alice
|
45
47
|
```
|
46
48
|
|
47
49
|
## Contributing
|
data/lib/ltsv_ng/formatter.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module LtsvNg
|
2
2
|
class Formatter < ::Logger::Formatter
|
3
3
|
def call(severity, timestamp, progname, msg)
|
4
|
-
raws = ["level:#{ severity }", "time:#{ timestamp }"]
|
4
|
+
raws = ["level:#{ severity }", "time:#{ timestamp }", "uuid:#{ SecureRandom.uuid }"]
|
5
5
|
case msg
|
6
6
|
when Hash
|
7
7
|
raws = msg.inject(raws) { |h, (key, value)| h << "#{key}:#{value}"; h }
|
data/lib/ltsv_ng/version.rb
CHANGED
data/lib/ltsv_ng.rb
CHANGED
data/spec/formatter_spec.rb
CHANGED
@@ -4,18 +4,20 @@ describe "LtsvNg::Formatter" do
|
|
4
4
|
let(:time) { Time.now }
|
5
5
|
let(:formatter) { LtsvNg::Formatter.new }
|
6
6
|
|
7
|
+
before(:each) { allow(SecureRandom).to receive(:uuid).and_return("b746d58e-e4c0-4f2b-86fd-f8ff78131745") }
|
8
|
+
|
7
9
|
describe "#call" do
|
8
10
|
context "String data log" do
|
9
11
|
it "returns LTSV Format text" do
|
10
12
|
text = formatter.call("INFO", time, nil, "foobar")
|
11
|
-
expect(text).to eq "level:INFO\ttime:#{time}\tmsg:foobar\n"
|
13
|
+
expect(text).to eq "level:INFO\ttime:#{time}\tuuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745\tmsg:foobar\n"
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
15
17
|
context "Hash data log" do
|
16
18
|
it "returns LTSV Format text" do
|
17
19
|
text = formatter.call("INFO", time, nil, { id: 123, name: "foobar"})
|
18
|
-
expect(text).to eq "level:INFO\ttime:#{time}\tid:123\tname:foobar\n"
|
20
|
+
expect(text).to eq "level:INFO\ttime:#{time}\tuuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745\tid:123\tname:foobar\n"
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
data/spec/logger_spec.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require_relative "spec_helper"
|
2
2
|
|
3
3
|
describe "LtsvNg::Logger" do
|
4
|
+
let(:time) { Time.now }
|
4
5
|
before do
|
5
6
|
@output = StringIO.new
|
6
7
|
@logger = LtsvNg::Logger.new(@output)
|
8
|
+
allow(SecureRandom).to receive(:uuid).and_return("b746d58e-e4c0-4f2b-86fd-f8ff78131745")
|
7
9
|
end
|
8
10
|
|
9
11
|
describe "#formatter" do
|
@@ -19,6 +21,8 @@ describe "LtsvNg::Logger" do
|
|
19
21
|
@output.seek(0)
|
20
22
|
ltsv = @output.read.strip.split("\t")
|
21
23
|
expect(ltsv).to include("level:INFO")
|
24
|
+
expect(ltsv).to include("time:#{time}")
|
25
|
+
expect(ltsv).to include("uuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745")
|
22
26
|
expect(ltsv).to include("msg:Test")
|
23
27
|
end
|
24
28
|
|
@@ -27,7 +31,9 @@ describe "LtsvNg::Logger" do
|
|
27
31
|
@output.seek(0)
|
28
32
|
ltsv = @output.read.strip.split("\t")
|
29
33
|
expect(ltsv).to include("level:INFO")
|
34
|
+
expect(ltsv).to include("time:#{time}")
|
30
35
|
expect(ltsv).to include("id:123")
|
36
|
+
expect(ltsv).to include("uuid:b746d58e-e4c0-4f2b-86fd-f8ff78131745")
|
31
37
|
expect(ltsv).to include("name:foobar")
|
32
38
|
end
|
33
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hirocaster
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|