alephant-logger-json 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42fbfe4b5a94e07af82f5b6f0e05bc6b9a946c08
4
- data.tar.gz: 67381b19f4fa00b7527131ce67ce8ffcd2f1fc57
3
+ metadata.gz: 1c033444e5c7be5a97534bce107a08c279301e01
4
+ data.tar.gz: 191119fd3d53a7be15706a68a45e141da55c5202
5
5
  SHA512:
6
- metadata.gz: e8210406b1afde2d6ee4d9ef8bfcab895fb2d03dac0b21e4457ebe7755cc271dda73d82027ffe8daf5e6f693f80a1c78dd02f486082c95e43142baa5696b2256
7
- data.tar.gz: 21139ea26ff8733c4278fe0bb0c264a3f3db65db41aaf14cd3c577906920f2659a730285644fb472dffb2e6be9b15b8b1782aef67105de042f20561c0d87c0b9
6
+ metadata.gz: 10d7ec2d6692efa3eae4f2800a13d1efa699fc6193fe7a86dfc25f1b91f43560671f197f013c098a5bff983da7f3d80916eaaac44029c3ea787747e4135bdf56
7
+ data.tar.gz: 3a78b33b93b986511427c1dccec853af56c6939fbf0373c71681389c075dd84e29a535b5dccc63520333a6ef9bf0d76d0fafa88564339872390a92033022c3ea
@@ -1,7 +1,7 @@
1
1
  module Alephant
2
2
  module Logger
3
3
  class JSON
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
6
6
  end
7
7
  end
@@ -12,9 +12,11 @@ module Alephant
12
12
  [:debug, :info, :warn, :error].each do |level|
13
13
  define_method(level) do |hash|
14
14
  return if hash.is_a? String
15
- hash["level"] = level.to_s
16
- hash["timestamp"] = Time.now.to_s
17
- hash = flatten_values_to_s hash unless @nesting
15
+ h = {
16
+ :timestamp => Time.now.to_s,
17
+ :level => level.to_s
18
+ }.merge hash
19
+ hash = flatten_values_to_s h unless @nesting
18
20
  @log_file.write(::JSON.generate(hash) + "\n")
19
21
  end
20
22
  end
@@ -21,8 +21,11 @@ describe Alephant::Logger::JSON do
21
21
  end
22
22
 
23
23
  it "writes JSON dump of hash to log with corresponding level key" do
24
+ allow(Time).to receive(:now).and_return("foobar")
25
+
24
26
  expect(log_file).to receive(:write) do |json_dump|
25
- expect(JSON.parse json_dump).to eq log_hash.merge("level" => level)
27
+ h = { "timestamp" => "foobar", "level" => level }
28
+ expect(JSON.parse json_dump).to eq h.merge log_hash
26
29
  end
27
30
 
28
31
  subject.send(level, log_hash)
@@ -36,6 +39,15 @@ describe Alephant::Logger::JSON do
36
39
 
37
40
  subject.send(level, log_hash)
38
41
  end
42
+
43
+ it "outputs the timestamp first" do
44
+ expect(log_file).to receive(:write) do |json_dump|
45
+ h = JSON.parse(json_dump)
46
+ expect(h.first[0].to_sym).to be :timestamp
47
+ end
48
+
49
+ subject.send(level, log_hash)
50
+ end
39
51
  end
40
52
 
41
53
  shared_context "nested log hash" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-logger-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Arnould
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler