sensu-logger 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/sensu-logger.gemspec +1 -1
- data/spec/logger_spec.rb +12 -12
- data/spec/stream_spec.rb +34 -34
- 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: d438ad15896f27c173da421d082fd92fc248eaa7
|
4
|
+
data.tar.gz: 5782ee85752b9458722bbc5f57065b81622426e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d61ec07629c6b621b0aa72fa7345bd7aec6d63f5227583c2d166cf454ba79956997088aba13201dd27d2b52dd24b2b85e3f7239dfe244954a944a94593999f7a
|
7
|
+
data.tar.gz: a46e3338e9e3f359c98769ef1746e3c888f52d7afabdda60853833e492fbe79cdce69d3cd99421d1c360c33020474b9fe18cca84738a3f3e4f45e216d46d0935
|
data/sensu-logger.gemspec
CHANGED
data/spec/logger_spec.rb
CHANGED
@@ -5,42 +5,42 @@ describe "Sensu::Logger" do
|
|
5
5
|
include Helpers
|
6
6
|
|
7
7
|
it "can provide the logger API" do
|
8
|
-
Sensu::Logger.
|
8
|
+
expect(Sensu::Logger).to respond_to(:setup, :get)
|
9
9
|
end
|
10
10
|
|
11
11
|
it "can set up a log stream" do
|
12
12
|
logger = Sensu::Logger.setup
|
13
|
-
logger.info("some info", {:foo => "bar"}).
|
13
|
+
expect(logger.info("some info", {:foo => "bar"})).to be(true)
|
14
14
|
logger.level = :warn
|
15
|
-
logger.info("some info", {:foo => "bar"}).
|
15
|
+
expect(logger.info("some info", {:foo => "bar"})).to be(false)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "can retrive the current log stream" do
|
19
19
|
logger = Sensu::Logger.setup
|
20
|
-
Sensu::Logger.get.
|
21
|
-
Sensu::Logger.get.
|
20
|
+
expect(Sensu::Logger.get).to eq(logger)
|
21
|
+
expect(Sensu::Logger.get).to eq(logger)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "can setup a log stream if one doesn't exist" do
|
25
25
|
logger = Sensu::Logger.get
|
26
|
-
logger.info("some info", {:foo => "bar"}).
|
26
|
+
expect(logger.info("some info", {:foo => "bar"})).to be(true)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "can setup a log stream with a log level and file" do
|
30
30
|
stdout = STDOUT.dup
|
31
31
|
file = Tempfile.new("sensu-logger")
|
32
32
|
logger = Sensu::Logger.setup(:log_level => :warn, :log_file => file.path)
|
33
|
-
logger.info("some info", {:foo => "bar"}).
|
34
|
-
logger.warn("a warning", {:foo => "bar"}).
|
33
|
+
expect(logger.info("some info", {:foo => "bar"})).to be(false)
|
34
|
+
expect(logger.warn("a warning", {:foo => "bar"})).to be(true)
|
35
35
|
file_contents = IO.read(file.path)
|
36
|
-
file_contents.
|
36
|
+
expect(file_contents).to match(/a warning/)
|
37
37
|
logger.reopen(stdout)
|
38
|
-
logger.warn("a warning", {:foo => "bar"}).
|
38
|
+
expect(logger.warn("a warning", {:foo => "bar"})).to be(true)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "can setup a log stream with options if one doesn't exist" do
|
42
42
|
logger = Sensu::Logger.get(:log_level => :warn)
|
43
|
-
logger.info("some info", {:foo => "bar"}).
|
44
|
-
logger.warn("a warning", {:foo => "bar"}).
|
43
|
+
expect(logger.info("some info", {:foo => "bar"})).to be(false)
|
44
|
+
expect(logger.warn("a warning", {:foo => "bar"})).to be(true)
|
45
45
|
end
|
46
46
|
end
|
data/spec/stream_spec.rb
CHANGED
@@ -10,60 +10,60 @@ describe "Sensu::Logger::Stream" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "can log events with different levels" do
|
13
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
14
|
-
@stream.info("some info", {:foo => "bar"}).
|
15
|
-
@stream.warn("a warning", {:foo => "bar"}).
|
16
|
-
@stream.error("an error", {:foo => "bar"}).
|
17
|
-
@stream.fatal("something exploded", {:foo => "bar"}).
|
13
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(false)
|
14
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
15
|
+
expect(@stream.warn("a warning", {:foo => "bar"})).to be(true)
|
16
|
+
expect(@stream.error("an error", {:foo => "bar"})).to be(true)
|
17
|
+
expect(@stream.fatal("something exploded", {:foo => "bar"})).to be(true)
|
18
18
|
@stream.level = :debug
|
19
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
20
|
-
@stream.info("some info", {:foo => "bar"}).
|
19
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(true)
|
20
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
21
21
|
@stream.level = :warn
|
22
|
-
@stream.info("some info", {:foo => "bar"}).
|
23
|
-
@stream.warn("a warning", {:foo => "bar"}).
|
22
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(false)
|
23
|
+
expect(@stream.warn("a warning", {:foo => "bar"})).to be(true)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "can reopen STDERR/STDOUT and redirect them to a log file" do
|
27
27
|
stdout = STDOUT.dup
|
28
28
|
file = Tempfile.new("sensu-logger")
|
29
29
|
@stream.reopen(file.path)
|
30
|
-
@stream.info("some info", {:foo => "bar"}).
|
30
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
31
31
|
@stream.reopen(stdout)
|
32
32
|
file_contents = IO.read(file.path)
|
33
|
-
file_contents.
|
34
|
-
file_contents.
|
35
|
-
file_contents.
|
33
|
+
expect(file_contents).to match(/timestamp/)
|
34
|
+
expect(file_contents).to match(/"message":"some info"/)
|
35
|
+
expect(file_contents).to match(/"foo":"bar"/)
|
36
36
|
@stream.reopen("/untouchable.log")
|
37
|
-
@stream.info("some info", {:foo => "bar"}).
|
37
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "can setup signal traps to toggle debug logging and reopen the log file" do
|
41
41
|
@stream.setup_signal_traps
|
42
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
43
|
-
@stream.info("some info", {:foo => "bar"}).
|
42
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(false)
|
43
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
44
44
|
Process.kill("TRAP", Process.pid)
|
45
45
|
sleep 0.5
|
46
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
47
|
-
@stream.info("some info", {:foo => "bar"}).
|
46
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(true)
|
47
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
48
48
|
Process.kill("TRAP", Process.pid)
|
49
49
|
sleep 0.5
|
50
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
51
|
-
@stream.info("some info", {:foo => "bar"}).
|
50
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(false)
|
51
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
52
52
|
@stream.level = :warn
|
53
|
-
@stream.info("some info", {:foo => "bar"}).
|
53
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(false)
|
54
54
|
Process.kill("TRAP", Process.pid)
|
55
55
|
sleep 0.5
|
56
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
57
|
-
@stream.info("some info", {:foo => "bar"}).
|
56
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(true)
|
57
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
58
58
|
Process.kill("TRAP", Process.pid)
|
59
59
|
sleep 0.5
|
60
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
61
|
-
@stream.info("some info", {:foo => "bar"}).
|
62
|
-
@stream.warn("a warning", {:foo => "bar"}).
|
60
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(false)
|
61
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(false)
|
62
|
+
expect(@stream.warn("a warning", {:foo => "bar"})).to be(true)
|
63
63
|
@stream.reopen(STDOUT)
|
64
64
|
Process.kill("USR2", Process.pid)
|
65
65
|
sleep 0.5
|
66
|
-
@stream.error("an error", {:foo => "bar"}).
|
66
|
+
expect(@stream.error("an error", {:foo => "bar"})).to be(true)
|
67
67
|
end
|
68
68
|
|
69
69
|
it "can operate as expected within the eventmachine reactor" do
|
@@ -71,10 +71,10 @@ describe "Sensu::Logger::Stream" do
|
|
71
71
|
stdout = STDOUT.dup
|
72
72
|
file = Tempfile.new("sensu-logger")
|
73
73
|
@stream.reopen(file.path)
|
74
|
-
@stream.debug("some debug info", {:foo => "bar"}).
|
75
|
-
@stream.info("some info", {:foo => "bar"}).
|
76
|
-
@stream.warn("a warning", {:foo => "bar"}).
|
77
|
-
@stream.error("an error", {:foo => "bar"}).
|
74
|
+
expect(@stream.debug("some debug info", {:foo => "bar"})).to be(false)
|
75
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
76
|
+
expect(@stream.warn("a warning", {:foo => "bar"})).to be(true)
|
77
|
+
expect(@stream.error("an error", {:foo => "bar"})).to be(true)
|
78
78
|
timer(1) do
|
79
79
|
@stream.reopen(stdout)
|
80
80
|
expected = [
|
@@ -88,7 +88,7 @@ describe "Sensu::Logger::Stream" do
|
|
88
88
|
parsed_line.delete(:timestamp)
|
89
89
|
parsed_line
|
90
90
|
end
|
91
|
-
parsed_contents.
|
91
|
+
expect(parsed_contents).to eq(expected)
|
92
92
|
async_done
|
93
93
|
end
|
94
94
|
end
|
@@ -100,11 +100,11 @@ describe "Sensu::Logger::Stream" do
|
|
100
100
|
async_wrapper do
|
101
101
|
@stream.reopen(file.path)
|
102
102
|
1000.times do
|
103
|
-
@stream.info("some info", {:foo => "bar"}).
|
103
|
+
expect(@stream.info("some info", {:foo => "bar"})).to be(true)
|
104
104
|
end
|
105
105
|
EM.stop
|
106
106
|
end
|
107
107
|
@stream.reopen(stdout)
|
108
|
-
IO.read(file.path).split("\n").size.
|
108
|
+
expect(IO.read(file.path).split("\n").size).to eq(1000)
|
109
109
|
end
|
110
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-em
|