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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 410eb98ad781584ffb894d45d3bbc912c836c54c
4
- data.tar.gz: 8d07103d322bde19bb36d32b79ca26631563d5bc
3
+ metadata.gz: 14be5c2fcdc34c05f693a36209a81f6cf36baff8
4
+ data.tar.gz: 441f8accb004f00caf648b59236987535ba275c2
5
5
  SHA512:
6
- metadata.gz: 4e812debf57093ea7ca9395f0748694d7cbeb304eea92d486a11c6e12731124cab4b5cd8c80f326601cebe9b92f4d7f54309da7c2a4e022a330bd73ccc46e577
7
- data.tar.gz: b0db9b99a5f9a646687839ad01cc0a6e05e6cca46843589acec10b63e229ad340b53b02a88d950a78f7dae968a59726da28afc473407e13f4a5fa1979a4070cf
6
+ metadata.gz: 5ee67bf03c5addaf509087c566c9416aa7c9dca9fcec91008c756a8442bb928385d223a9053f3f3041c6fdcdb8da20c81c70398c1307fa2a06fcd31a04d21935
7
+ data.tar.gz: 66f47c99844e5a16b3ce7c632100c26c92154898efa02c8a29aa9cffc860a96ba8d58054450ab6ad39d8ed3b3bc7139127c81223e34b890d61b2b8421a9f12e5
@@ -1,14 +1,21 @@
1
1
  module LtsvNg
2
2
  class Formatter < ::Logger::Formatter
3
3
  def call(severity, timestamp, progname, msg)
4
- raws = ["level:#{ severity }", "time:#{ timestamp }", "uuid:#{ SecureRandom.uuid }"]
4
+ raws = { level: severity, time: timestamp, uuid: SecureRandom.uuid }
5
5
  case msg
6
6
  when Hash
7
- raws = msg.inject(raws) { |h, (key, value)| h << "#{key}:#{value}"; h }
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 << "msg:#{ msg }"
15
+ raws[:msg] = msg
10
16
  end
11
- "#{raws.join("\t")}\n"
17
+
18
+ raws.inject(Array.new) { |h, (key, value)| h << "#{key}:#{value}" }.join("\t") + "\n"
12
19
  end
13
20
  end
14
21
  end
@@ -1,3 +1,3 @@
1
1
  module LtsvNg
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/ltsv_ng.gemspec CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "timecop"
24
25
  end
@@ -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
- let(:time) { Time.now }
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:#{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:#{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
@@ -96,3 +96,4 @@ RSpec.configure do |config|
96
96
  end
97
97
 
98
98
  require "ltsv_ng"
99
+ require "timecop"
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.2
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