alephant-logger-json 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/alephant-logger-json.gemspec +3 -2
- data/lib/alephant/logger/json/version.rb +1 -1
- data/lib/alephant/logger/json.rb +10 -0
- data/spec/alephant/logger/json_spec.rb +30 -1
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 771869cbd5bcad995127e6ef602ec4ae3c1c6177
|
4
|
+
data.tar.gz: 4cd2f63c8aba00076408f9f42ecd33c6dc1a3b48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb3f8e8dfaf453a946aff808903601b49881d199740b248db192bf4837a05b8fc47be1e290983baf7a01b91e896f2135b75416ccfd08c5c1cf0182cdc44957f0
|
7
|
+
data.tar.gz: 4c5853cde0064536adb6c03c080acd884470e2b9885c81ec293efd6939453d5ba04fcc58236afa149f2c9f726f43485caadd96f6f286df2abe5dda8f833afba5
|
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
-
spec.add_development_dependency "rake"
|
23
|
-
spec.add_development_dependency "rspec"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
24
|
spec.add_development_dependency "rspec-nc"
|
25
25
|
spec.add_development_dependency "rake-rspec"
|
26
|
+
spec.add_development_dependency "pry"
|
26
27
|
end
|
data/lib/alephant/logger/json.rb
CHANGED
@@ -12,8 +12,10 @@ 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
|
+
@@session = -> { "n/a" } unless defined? @@session
|
15
16
|
h = {
|
16
17
|
:timestamp => Time.now.to_s,
|
18
|
+
:uuid => @@session.(),
|
17
19
|
:level => level.to_s
|
18
20
|
}.merge hash
|
19
21
|
hash = flatten_values_to_s h unless @nesting
|
@@ -21,6 +23,14 @@ module Alephant
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
26
|
+
def self.session(fn)
|
27
|
+
@@session = fn
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.session?
|
31
|
+
defined?(@@session)
|
32
|
+
end
|
33
|
+
|
24
34
|
private
|
25
35
|
|
26
36
|
def flatten_values_to_s(hash)
|
@@ -7,6 +7,7 @@ describe Alephant::Logger::JSON do
|
|
7
7
|
described_class.new log_path
|
8
8
|
end
|
9
9
|
|
10
|
+
let(:fn) { -> { "foo" } }
|
10
11
|
let(:log_path) { "/log/path.log" }
|
11
12
|
let(:log_file) { instance_double File }
|
12
13
|
|
@@ -24,7 +25,7 @@ describe Alephant::Logger::JSON do
|
|
24
25
|
allow(Time).to receive(:now).and_return("foobar")
|
25
26
|
|
26
27
|
expect(log_file).to receive(:write) do |json_dump|
|
27
|
-
h = { "timestamp" => "foobar", "level" => level }
|
28
|
+
h = { "timestamp" => "foobar", "uuid" => "n/a", "level" => level }
|
28
29
|
expect(JSON.parse json_dump).to eq h.merge log_hash
|
29
30
|
end
|
30
31
|
|
@@ -48,6 +49,34 @@ describe Alephant::Logger::JSON do
|
|
48
49
|
|
49
50
|
subject.send(level, log_hash)
|
50
51
|
end
|
52
|
+
|
53
|
+
it "displays a default session value if a custom function is not provided" do
|
54
|
+
expect(log_file).to receive(:write) do |json_dump|
|
55
|
+
h = JSON.parse(json_dump)
|
56
|
+
expect(h["uuid"]).to eq "n/a"
|
57
|
+
end
|
58
|
+
|
59
|
+
subject.send(level, log_hash)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "displays a custom session value when provided a user defined function" do
|
63
|
+
expect(log_file).to receive(:write) do |json_dump|
|
64
|
+
h = JSON.parse(json_dump)
|
65
|
+
expect(h["uuid"]).to eq "foo"
|
66
|
+
end
|
67
|
+
|
68
|
+
::Alephant::Logger::JSON.session fn
|
69
|
+
subject.send(level, log_hash)
|
70
|
+
::Alephant::Logger::JSON.session -> { "n/a" }
|
71
|
+
end
|
72
|
+
|
73
|
+
it "provides a static method for checking if a session has been set" do
|
74
|
+
::Alephant::Logger::JSON.session fn
|
75
|
+
expect(::Alephant::Logger::JSON.session?).to eq "class variable"
|
76
|
+
|
77
|
+
::Alephant::Logger::JSON.remove_class_variable :@@session
|
78
|
+
expect(::Alephant::Logger::JSON.session?).to eq nil
|
79
|
+
end
|
51
80
|
end
|
52
81
|
|
53
82
|
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.
|
4
|
+
version: 0.3.0
|
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-03-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec-nc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: alephant-logger driver enabling structured logging in JSON
|
84
98
|
email:
|
85
99
|
- dan@arnould.co.uk
|