alephant-logger-json 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/logger/json/version.rb +1 -1
- data/lib/alephant/logger/json.rb +5 -3
- data/spec/alephant/logger/json_spec.rb +13 -1
- 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: 1c033444e5c7be5a97534bce107a08c279301e01
|
4
|
+
data.tar.gz: 191119fd3d53a7be15706a68a45e141da55c5202
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10d7ec2d6692efa3eae4f2800a13d1efa699fc6193fe7a86dfc25f1b91f43560671f197f013c098a5bff983da7f3d80916eaaac44029c3ea787747e4135bdf56
|
7
|
+
data.tar.gz: 3a78b33b93b986511427c1dccec853af56c6939fbf0373c71681389c075dd84e29a535b5dccc63520333a6ef9bf0d76d0fafa88564339872390a92033022c3ea
|
data/lib/alephant/logger/json.rb
CHANGED
@@ -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
|
-
|
16
|
-
|
17
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|