alephant-logger 1.1.0 → 1.1.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.rb +9 -25
- data/lib/alephant/logger/base.rb +25 -0
- data/lib/alephant/logger/version.rb +1 -1
- data/lib/alephant/logger_factory.rb +9 -0
- data/spec/logger_base_spec.rb +33 -0
- data/spec/logger_spec.rb +3 -35
- data/spec/spec_helper.rb +3 -4
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5d1499280f31079a470dd60e74786a9393802b3
|
4
|
+
data.tar.gz: 371124eae62711cdedeadf70e1f6e5827ece2e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 643fa7bab726821bef7a1b6e2ad9c280e75679251f72879fd6c0817a039a3980b3c08a06b164c03ddacdd0383066b45f43a71564919d76689d959a815f5e2616
|
7
|
+
data.tar.gz: f660dee91ea4db95ec0ace00c252717da051e75d70374d62b8908c7ceb696f86286c81d6e0e1d733bba9447b3bfafe9ed5c96410303eecafa33e2e15ae78f81e
|
data/lib/alephant/logger.rb
CHANGED
@@ -1,33 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "alephant/logger/version"
|
2
|
+
require "alephant/logger_factory"
|
3
|
+
require "logger"
|
3
4
|
|
4
5
|
module Alephant
|
5
6
|
module Logger
|
6
|
-
|
7
|
-
Logger.new drivers
|
8
|
-
end
|
9
|
-
|
10
|
-
class Logger
|
11
|
-
def initialize(drivers)
|
12
|
-
@drivers = drivers << ::Logger.new(STDOUT)
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing(name, *args)
|
16
|
-
drivers.each do |driver|
|
17
|
-
driver.send(name, *args) if driver.respond_to? name
|
18
|
-
end
|
19
|
-
end
|
7
|
+
@@logger = Alephant::LoggerFactory.create []
|
20
8
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
9
|
+
def logger
|
10
|
+
@@logger
|
11
|
+
end
|
28
12
|
|
29
|
-
|
13
|
+
def self.setup(*drivers)
|
14
|
+
@@logger = Alephant::LoggerFactory.create(drivers.flatten)
|
30
15
|
end
|
31
16
|
end
|
32
17
|
end
|
33
|
-
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Alephant
|
2
|
+
module Logger
|
3
|
+
class Base
|
4
|
+
def initialize(drivers)
|
5
|
+
@drivers = drivers << ::Logger.new(STDOUT)
|
6
|
+
end
|
7
|
+
|
8
|
+
def method_missing(name, *args)
|
9
|
+
drivers.each do |driver|
|
10
|
+
driver.send(name, *args) if driver.respond_to? name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def respond_to?(name)
|
15
|
+
drivers.any? do |driver|
|
16
|
+
driver.respond_to?(name) || super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :drivers
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Alephant::Logger::Base do
|
4
|
+
describe "#info" do
|
5
|
+
context "no logger drivers given" do
|
6
|
+
subject { Alephant::Logger::Base.new [] }
|
7
|
+
|
8
|
+
specify do
|
9
|
+
expect_any_instance_of(::Logger).to receive(:info).with "msg"
|
10
|
+
|
11
|
+
subject.info "msg"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "logger drivers given" do
|
16
|
+
subject { Alephant::Logger::Base.new [driver] }
|
17
|
+
|
18
|
+
let(:driver) { double }
|
19
|
+
|
20
|
+
it "responding drivers receive method calls" do
|
21
|
+
expect(driver).to receive(:metric).with("foo")
|
22
|
+
|
23
|
+
subject.metric("foo")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "::Logger is always used" do
|
27
|
+
expect_any_instance_of(::Logger).to receive(:info).with "foo"
|
28
|
+
|
29
|
+
subject.info "foo"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/logger_spec.rb
CHANGED
@@ -1,41 +1,9 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe Alephant::Logger do
|
4
|
-
describe ".
|
4
|
+
describe ".setup" do
|
5
5
|
specify do
|
6
|
-
expect(subject.
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe Alephant::Logger::Logger do
|
12
|
-
describe "#info" do
|
13
|
-
context "no logger drivers given" do
|
14
|
-
subject { Alephant::Logger::Logger.new [] }
|
15
|
-
|
16
|
-
specify do
|
17
|
-
expect_any_instance_of(::Logger).to receive(:info).with "msg"
|
18
|
-
|
19
|
-
subject.info "msg"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context "logger drivers given" do
|
24
|
-
subject { Alephant::Logger::Logger.new [driver] }
|
25
|
-
|
26
|
-
let(:driver) { double }
|
27
|
-
|
28
|
-
it "responding drivers receive method calls" do
|
29
|
-
expect(driver).to receive(:metric).with("foo")
|
30
|
-
|
31
|
-
subject.metric("foo")
|
32
|
-
end
|
33
|
-
|
34
|
-
it "::Logger is always used" do
|
35
|
-
expect_any_instance_of(::Logger).to receive(:info).with "foo"
|
36
|
-
|
37
|
-
subject.info "foo"
|
38
|
-
end
|
6
|
+
expect(subject.setup).to be_a Alephant::Logger::Base
|
39
7
|
end
|
40
8
|
end
|
41
9
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
@@ -153,7 +153,10 @@ files:
|
|
153
153
|
- Rakefile
|
154
154
|
- alephant-logger.gemspec
|
155
155
|
- lib/alephant/logger.rb
|
156
|
+
- lib/alephant/logger/base.rb
|
156
157
|
- lib/alephant/logger/version.rb
|
158
|
+
- lib/alephant/logger_factory.rb
|
159
|
+
- spec/logger_base_spec.rb
|
157
160
|
- spec/logger_spec.rb
|
158
161
|
- spec/spec_helper.rb
|
159
162
|
homepage: ''
|
@@ -181,5 +184,6 @@ signing_key:
|
|
181
184
|
specification_version: 4
|
182
185
|
summary: Logger functionality for Alephant
|
183
186
|
test_files:
|
187
|
+
- spec/logger_base_spec.rb
|
184
188
|
- spec/logger_spec.rb
|
185
189
|
- spec/spec_helper.rb
|