steno 1.2.4 → 1.3.4
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 +5 -13
- data/Rakefile +0 -1
- data/lib/steno/codec/json.rb +14 -1
- data/lib/steno/config.rb +4 -0
- data/lib/steno/json_prettifier.rb +1 -1
- data/lib/steno/sink/syslog.rb +5 -3
- data/lib/steno/version.rb +1 -1
- data/spec/support/shared_context_specs.rb +1 -1
- data/spec/unit/config_spec.rb +56 -48
- data/spec/unit/context_spec.rb +6 -6
- data/spec/unit/core_ext_spec.rb +6 -6
- data/spec/unit/json_codec_spec.rb +26 -6
- data/spec/unit/json_prettifier_spec.rb +4 -4
- data/spec/unit/log_level_spec.rb +4 -4
- data/spec/unit/logger_spec.rb +20 -20
- data/spec/unit/record_spec.rb +6 -6
- data/spec/unit/sink/fluentd_spec.rb +7 -7
- data/spec/unit/sink/io_spec.rb +19 -19
- data/spec/unit/sink/syslog_spec.rb +16 -16
- data/spec/unit/steno_spec.rb +12 -12
- data/spec/unit/tagged_logger_spec.rb +11 -9
- data/steno.gemspec +1 -2
- metadata +17 -31
checksums.yaml
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
|
|
5
|
-
data.tar.gz: !binary |-
|
|
6
|
-
MzUzMjIwZTNjYTAzYWIyZDE2MmNmNTNiOTBkMzIzZmRiMDJmMGFkOQ==
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9ae74f2bde35a6d8f17503cb1cd7bff4eb458b78
|
|
4
|
+
data.tar.gz: a3939b000fb9d0aaf3c7ade1231008d24e212a6e
|
|
7
5
|
SHA512:
|
|
8
|
-
metadata.gz:
|
|
9
|
-
|
|
10
|
-
ZDRlYjY5NzEzMjA5NmI0NTQwMmE0MjBiNDBkNTc2NDQ2ZGIxZTVkNDhhNzA2
|
|
11
|
-
MDFiNWMxMjhhOTA2YzUyYzMxN2ZhMzk1YjZlYmIzYjdkZDk2ZjM=
|
|
12
|
-
data.tar.gz: !binary |-
|
|
13
|
-
Zjc3ZmVkY2QzNWZjZDUxYWNiYWQ5MWRhYjlkNjM2ZTg1Nzc0MDBhNWNlZWY4
|
|
14
|
-
ZDUzYjg1YWJiZDUxYzlkN2E0ZDg1NTk5YzMwMzdiMzRkMGZhNDdhOTMyMWUw
|
|
15
|
-
ZDE0YTVmNTBkZWI1MmNjNGEyNjgyOWI1YWQyYTRkNjgzNTFhZWY=
|
|
6
|
+
metadata.gz: c12db2c17088b015b24cbb6744d66b9ad7880a93c302b2dd16a0f7d896c38342677cf935f9b478f66c0d93988677bda9611c865af2a6aaa4baedb91bd88f3d1c
|
|
7
|
+
data.tar.gz: 23b73d7a6eb69d64d1e33292ba3a97ae5a5dcc617e9d09112a2e0e03c74abbfd941909a3622b120832ade5e9ee80aa35fe8f7dbe3fcc74cde74c864aa5c7f5f0
|
data/Rakefile
CHANGED
data/lib/steno/codec/json.rb
CHANGED
|
@@ -8,6 +8,11 @@ module Steno
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
class Steno::Codec::Json < Steno::Codec::Base
|
|
11
|
+
|
|
12
|
+
def initialize(opts = {})
|
|
13
|
+
@iso8601_timestamps = opts[:iso8601_timestamps] || false
|
|
14
|
+
end
|
|
15
|
+
|
|
11
16
|
def encode_record(record)
|
|
12
17
|
msg =
|
|
13
18
|
if record.message.valid_encoding?
|
|
@@ -31,6 +36,14 @@ class Steno::Codec::Json < Steno::Codec::Base
|
|
|
31
36
|
"method" => record.method,
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
if iso8601_timestamps?
|
|
40
|
+
h["timestamp"] = Time.at(record.timestamp).utc.iso8601(6)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Yajl::Encoder.encode(h) + "\n"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def iso8601_timestamps?
|
|
47
|
+
@iso8601_timestamps
|
|
35
48
|
end
|
|
36
49
|
end
|
data/lib/steno/config.rb
CHANGED
|
@@ -41,6 +41,10 @@ class Steno::Config
|
|
|
41
41
|
:default_log_level => level.nil? ? :info : level.to_sym
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
if hash[:iso8601_timestamps]
|
|
45
|
+
opts[:codec] = Steno::Codec::Json.new(:iso8601_timestamps => true)
|
|
46
|
+
end
|
|
47
|
+
|
|
44
48
|
if hash[:file]
|
|
45
49
|
max_retries = hash[:max_retries]
|
|
46
50
|
opts[:sinks] << Steno::Sink::IO.for_file(hash[:file], :max_retries => max_retries)
|
|
@@ -50,7 +50,7 @@ class Steno::JsonPrettifier
|
|
|
50
50
|
|
|
51
51
|
exists = nil
|
|
52
52
|
pred_meth = "check_#{field_name}".to_sym
|
|
53
|
-
if respond_to?(pred_meth)
|
|
53
|
+
if respond_to?(pred_meth, true)
|
|
54
54
|
exists = send(pred_meth, record)
|
|
55
55
|
elsif record.respond_to?(:has_key?)
|
|
56
56
|
exists = record.has_key?(field_name)
|
data/lib/steno/sink/syslog.rb
CHANGED
|
@@ -3,7 +3,7 @@ unless Steno::Sink::WINDOWS
|
|
|
3
3
|
|
|
4
4
|
require "singleton"
|
|
5
5
|
require "thread"
|
|
6
|
-
require "syslog"
|
|
6
|
+
require "syslog/logger"
|
|
7
7
|
|
|
8
8
|
class Steno::Sink::Syslog < Steno::Sink::Base
|
|
9
9
|
include Singleton
|
|
@@ -30,7 +30,9 @@ unless Steno::Sink::WINDOWS
|
|
|
30
30
|
|
|
31
31
|
def open(identity)
|
|
32
32
|
@identity = identity
|
|
33
|
-
|
|
33
|
+
|
|
34
|
+
Syslog::Logger.new(@identity)
|
|
35
|
+
@syslog = Syslog::Logger.syslog
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def add_record(record)
|
|
@@ -57,4 +59,4 @@ unless Steno::Sink::WINDOWS
|
|
|
57
59
|
record.data)
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
|
-
end
|
|
62
|
+
end
|
data/lib/steno/version.rb
CHANGED
data/spec/unit/config_spec.rb
CHANGED
|
@@ -11,27 +11,27 @@ describe Steno::Config do
|
|
|
11
11
|
@log_path = "some_file"
|
|
12
12
|
|
|
13
13
|
@mock_sink_file = double("sink")
|
|
14
|
-
@mock_sink_file.
|
|
15
|
-
Steno::Sink::IO.
|
|
14
|
+
expect(@mock_sink_file).to receive(:codec=)
|
|
15
|
+
expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
|
|
16
16
|
:max_retries => 5)
|
|
17
17
|
.and_return(@mock_sink_file)
|
|
18
18
|
|
|
19
19
|
@mock_sink_eventlog = double("sink")
|
|
20
|
-
@mock_sink_eventlog.
|
|
21
|
-
@mock_sink_eventlog.
|
|
22
|
-
Steno::Sink::Eventlog.
|
|
20
|
+
expect(@mock_sink_eventlog).to receive(:codec=)
|
|
21
|
+
expect(@mock_sink_eventlog).to receive(:open).with("test")
|
|
22
|
+
expect(Steno::Sink::Eventlog).to receive(:instance).twice()
|
|
23
23
|
.and_return(@mock_sink_eventlog)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
after :each do
|
|
27
27
|
@config = Steno::Config.from_hash(@hash)
|
|
28
28
|
|
|
29
|
-
@config.default_log_level.
|
|
30
|
-
@config.context.
|
|
31
|
-
@config.codec.
|
|
29
|
+
expect(@config.default_log_level).to eq(:debug2)
|
|
30
|
+
expect(@config.context.class).to eq(Steno::Context::Null)
|
|
31
|
+
expect(@config.codec.class).to eq(Steno::Codec::Json)
|
|
32
32
|
|
|
33
|
-
@config.sinks.size.
|
|
34
|
-
@config.sinks.
|
|
33
|
+
expect(@config.sinks.size).to eq(2)
|
|
34
|
+
expect(@config.sinks).to match_array([@mock_sink_file, @mock_sink_eventlog])
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
it "should work for symbolized keys" do
|
|
@@ -61,27 +61,27 @@ describe Steno::Config do
|
|
|
61
61
|
@log_path = "some_file"
|
|
62
62
|
|
|
63
63
|
@mock_sink_file = double("sink")
|
|
64
|
-
@mock_sink_file.
|
|
65
|
-
Steno::Sink::IO.
|
|
64
|
+
allow(@mock_sink_file).to receive(:codec=)
|
|
65
|
+
expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
|
|
66
66
|
:max_retries => 5)
|
|
67
67
|
.and_return(@mock_sink_file)
|
|
68
68
|
|
|
69
69
|
@mock_sink_syslog = double("sink")
|
|
70
|
-
@mock_sink_syslog.
|
|
71
|
-
@mock_sink_syslog.
|
|
72
|
-
Steno::Sink::Syslog.
|
|
70
|
+
expect(@mock_sink_syslog).to receive(:codec=)
|
|
71
|
+
expect(@mock_sink_syslog).to receive(:open).with("test")
|
|
72
|
+
expect(Steno::Sink::Syslog).to receive(:instance).twice()
|
|
73
73
|
.and_return(@mock_sink_syslog)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
after :each do
|
|
77
77
|
@config = Steno::Config.from_hash(@hash)
|
|
78
78
|
|
|
79
|
-
@config.default_log_level.
|
|
80
|
-
@config.context.
|
|
81
|
-
@config.codec.
|
|
79
|
+
expect(@config.default_log_level).to eq(:debug2)
|
|
80
|
+
expect(@config.context.class).to eq(Steno::Context::Null)
|
|
81
|
+
expect(@config.codec.class).to eq(Steno::Codec::Json)
|
|
82
82
|
|
|
83
|
-
@config.sinks.size.
|
|
84
|
-
@config.sinks.
|
|
83
|
+
expect(@config.sinks.size).to eq(2)
|
|
84
|
+
expect(@config.sinks).to match_array([@mock_sink_file, @mock_sink_syslog])
|
|
85
85
|
end
|
|
86
86
|
|
|
87
87
|
it "should work for symbolized keys" do
|
|
@@ -123,67 +123,75 @@ describe Steno::Config do
|
|
|
123
123
|
|
|
124
124
|
config = Steno::Config.from_file(@config_path)
|
|
125
125
|
|
|
126
|
-
config.sinks.size.
|
|
127
|
-
config.sinks[0].class.
|
|
126
|
+
expect(config.sinks.size).to eq(1)
|
|
127
|
+
expect(config.sinks[0].class).to eq(Steno::Sink::IO)
|
|
128
128
|
|
|
129
|
-
config.default_log_level.
|
|
129
|
+
expect(config.default_log_level).to eq(:info)
|
|
130
130
|
|
|
131
|
-
config.context.
|
|
131
|
+
expect(config.context.class).to eq(Steno::Context::Null)
|
|
132
132
|
|
|
133
|
-
config.codec.
|
|
133
|
+
expect(config.codec.class).to eq(Steno::Codec::Json)
|
|
134
|
+
expect(config.codec.iso8601_timestamps?).to eq(false)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it "should configure json codec with readable dates if iso8601_timestamps is true" do
|
|
138
|
+
write_config(@config_path, {"iso8601_timestamps" => "true"})
|
|
139
|
+
config = Steno::Config.from_file(@config_path)
|
|
140
|
+
expect(config.codec.class).to eq(Steno::Codec::Json)
|
|
141
|
+
expect(config.codec.iso8601_timestamps?).to eq(true)
|
|
134
142
|
end
|
|
135
143
|
|
|
136
144
|
it "should set the default_log_level if a key with the same name is supplied" do
|
|
137
145
|
write_config(@config_path, {"level" => "debug2"})
|
|
138
|
-
Steno::Config.from_file(@config_path).default_log_level.
|
|
146
|
+
expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
|
|
139
147
|
|
|
140
148
|
write_config(@config_path, {"default_log_level" => "debug2"})
|
|
141
|
-
Steno::Config.from_file(@config_path).default_log_level.
|
|
149
|
+
expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
|
|
142
150
|
end
|
|
143
151
|
|
|
144
152
|
it "should read the 'level' key if both default_log_level and level are spscified" do
|
|
145
153
|
write_config(@config_path, {"level" => "debug2",
|
|
146
154
|
"default_log_level" => "warn"})
|
|
147
|
-
Steno::Config.from_file(@config_path).default_log_level.
|
|
155
|
+
expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
|
|
148
156
|
end
|
|
149
157
|
|
|
150
158
|
it "should add a file sink if the 'file' key is specified" do
|
|
151
159
|
write_config(@config_path, {"file" => @log_path, "max_retries" => 2})
|
|
152
160
|
mock_sink = double("sink")
|
|
153
|
-
mock_sink.
|
|
161
|
+
expect(mock_sink).to receive(:codec=)
|
|
154
162
|
|
|
155
|
-
Steno::Sink::IO.
|
|
163
|
+
expect(Steno::Sink::IO).to receive(:for_file).
|
|
156
164
|
with(@log_path, :max_retries => 2).and_return(mock_sink)
|
|
157
165
|
config = Steno::Config.from_file(@config_path)
|
|
158
|
-
config.sinks.size.
|
|
159
|
-
config.sinks[0].
|
|
166
|
+
expect(config.sinks.size).to eq(1)
|
|
167
|
+
expect(config.sinks[0]).to eq(mock_sink)
|
|
160
168
|
end
|
|
161
169
|
|
|
162
170
|
if Steno::Sink::WINDOWS
|
|
163
171
|
it "should add a event sink if the 'eventlog' key is specified" do
|
|
164
172
|
write_config(@config_path, {"eventlog" => "test"})
|
|
165
173
|
mock_sink = double("sink")
|
|
166
|
-
mock_sink.
|
|
167
|
-
mock_sink.
|
|
174
|
+
expect(mock_sink).to receive(:open).with("test")
|
|
175
|
+
expect(mock_sink).to receive(:codec=)
|
|
168
176
|
|
|
169
|
-
Steno::Sink::Eventlog.
|
|
177
|
+
expect(Steno::Sink::Eventlog).to receive(:instance).twice().and_return(mock_sink)
|
|
170
178
|
|
|
171
179
|
config = Steno::Config.from_file(@config_path)
|
|
172
|
-
config.sinks.size.
|
|
173
|
-
config.sinks[0].
|
|
180
|
+
expect(config.sinks.size).to eq(1)
|
|
181
|
+
expect(config.sinks[0]).to eq(mock_sink)
|
|
174
182
|
end
|
|
175
183
|
else
|
|
176
184
|
it "should add a syslog sink if the 'syslog' key is specified" do
|
|
177
185
|
write_config(@config_path, {"syslog" => "test"})
|
|
178
186
|
mock_sink = double("sink")
|
|
179
|
-
mock_sink.
|
|
180
|
-
mock_sink.
|
|
187
|
+
expect(mock_sink).to receive(:open).with("test")
|
|
188
|
+
expect(mock_sink).to receive(:codec=)
|
|
181
189
|
|
|
182
|
-
Steno::Sink::Syslog.
|
|
190
|
+
expect(Steno::Sink::Syslog).to receive(:instance).twice().and_return(mock_sink)
|
|
183
191
|
|
|
184
192
|
config = Steno::Config.from_file(@config_path)
|
|
185
|
-
config.sinks.size.
|
|
186
|
-
config.sinks[0].
|
|
193
|
+
expect(config.sinks.size).to eq(1)
|
|
194
|
+
expect(config.sinks[0]).to eq(mock_sink)
|
|
187
195
|
end
|
|
188
196
|
end
|
|
189
197
|
|
|
@@ -192,13 +200,13 @@ describe Steno::Config do
|
|
|
192
200
|
it "should add an io sink to stdout if no sinks are explicitly specified in the config file" do
|
|
193
201
|
write_config(@config_path, {})
|
|
194
202
|
mock_sink = double("sink")
|
|
195
|
-
mock_sink.
|
|
203
|
+
expect(mock_sink).to receive(:codec=)
|
|
196
204
|
|
|
197
|
-
Steno::Sink::IO.
|
|
205
|
+
expect(Steno::Sink::IO).to receive(:new).with(STDOUT).and_return(mock_sink)
|
|
198
206
|
|
|
199
207
|
config = Steno::Config.from_file(@config_path)
|
|
200
|
-
config.sinks.size.
|
|
201
|
-
config.sinks[0].
|
|
208
|
+
expect(config.sinks.size).to eq(1)
|
|
209
|
+
expect(config.sinks[0]).to eq(mock_sink)
|
|
202
210
|
end
|
|
203
211
|
|
|
204
212
|
it "should merge supplied overrides with the file based config" do
|
|
@@ -208,8 +216,8 @@ describe Steno::Config do
|
|
|
208
216
|
config = Steno::Config.from_file(@config_path,
|
|
209
217
|
:default_log_level => "warn",
|
|
210
218
|
:context => context)
|
|
211
|
-
config.context.
|
|
212
|
-
config.default_log_level.
|
|
219
|
+
expect(config.context).to eq(context)
|
|
220
|
+
expect(config.default_log_level).to eq(:warn)
|
|
213
221
|
end
|
|
214
222
|
end
|
|
215
223
|
|
data/spec/unit/context_spec.rb
CHANGED
|
@@ -6,9 +6,9 @@ describe Steno::Context::Null do
|
|
|
6
6
|
let(:context) { Steno::Context::Null.new }
|
|
7
7
|
|
|
8
8
|
it "should store no data" do
|
|
9
|
-
context.data.
|
|
9
|
+
expect(context.data).to eq({})
|
|
10
10
|
context.data["foo"] = "bar"
|
|
11
|
-
context.data.
|
|
11
|
+
expect(context.data).to eq({})
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -25,12 +25,12 @@ describe Steno::Context::ThreadLocal do
|
|
|
25
25
|
context.data["thread"] = "t1"
|
|
26
26
|
b1.release
|
|
27
27
|
b2.wait
|
|
28
|
-
context.data["thread"].
|
|
28
|
+
expect(context.data["thread"]).to eq("t1")
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
t2 = Thread.new do
|
|
32
32
|
b1.wait
|
|
33
|
-
context.data["thread"].
|
|
33
|
+
expect(context.data["thread"]).to be_nil
|
|
34
34
|
context.data["thread"] = "t2"
|
|
35
35
|
b2.release
|
|
36
36
|
end
|
|
@@ -47,14 +47,14 @@ describe Steno::Context::FiberLocal do
|
|
|
47
47
|
|
|
48
48
|
it "should store data local to fibers" do
|
|
49
49
|
f2 = Fiber.new do
|
|
50
|
-
context.data["fiber"].
|
|
50
|
+
expect(context.data["fiber"]).to be_nil
|
|
51
51
|
context.data["fiber"] = "f2"
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
f1 = Fiber.new do
|
|
55
55
|
context.data["fiber"] = "f1"
|
|
56
56
|
f2.resume
|
|
57
|
-
context.data["fiber"].
|
|
57
|
+
expect(context.data["fiber"]).to eq("f1")
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
f1.resume
|
data/spec/unit/core_ext_spec.rb
CHANGED
|
@@ -11,8 +11,8 @@ describe Module do
|
|
|
11
11
|
describe "#logger" do
|
|
12
12
|
it "should request a logger named after itself" do
|
|
13
13
|
x = Foo.logger
|
|
14
|
-
x.
|
|
15
|
-
x.name.
|
|
14
|
+
expect(x).to be_a(Steno::Logger)
|
|
15
|
+
expect(x.name).to include("Foo")
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end
|
|
@@ -21,8 +21,8 @@ describe Class do
|
|
|
21
21
|
describe "#logger" do
|
|
22
22
|
it "should request a logger named after itself" do
|
|
23
23
|
x = Foo::Bar.logger
|
|
24
|
-
x.
|
|
25
|
-
x.name.
|
|
24
|
+
expect(x).to be_a(Steno::Logger)
|
|
25
|
+
expect(x.name).to include("Foo::Bar")
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
end
|
|
@@ -31,8 +31,8 @@ describe Object do
|
|
|
31
31
|
describe "#logger" do
|
|
32
32
|
it "should request a logger named after its class" do
|
|
33
33
|
x = Foo::Bar.new.logger
|
|
34
|
-
x.
|
|
35
|
-
x.name.
|
|
34
|
+
expect(x).to be_a(Steno::Logger)
|
|
35
|
+
expect(x.name).to include("Foo::Bar")
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
end
|
|
@@ -7,34 +7,54 @@ describe Steno::Codec::Json do
|
|
|
7
7
|
describe "#encode_record" do
|
|
8
8
|
it "should encode records as json hashes" do
|
|
9
9
|
parsed = Yajl::Parser.parse(codec.encode_record(record))
|
|
10
|
-
parsed.class.
|
|
10
|
+
expect(parsed.class).to eq(Hash)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
it "should encode the timestamp as a float" do
|
|
14
14
|
parsed = Yajl::Parser.parse(codec.encode_record(record))
|
|
15
|
-
parsed["timestamp"].class.
|
|
15
|
+
expect(parsed["timestamp"].class).to eq(Float)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
it "should escape newlines" do
|
|
19
19
|
rec = make_record(:message => "newline\ntest")
|
|
20
|
-
codec.encode_record(rec).
|
|
20
|
+
expect(codec.encode_record(rec)).to match(/newline\\ntest/)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "should escape carriage returns" do
|
|
24
24
|
rec = make_record(:message => "newline\rtest")
|
|
25
|
-
codec.encode_record(rec).
|
|
25
|
+
expect(codec.encode_record(rec)).to match(/newline\\rtest/)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
it "should allow messages with valid encodings to pass through untouched" do
|
|
29
29
|
msg = "HI\u2600"
|
|
30
30
|
rec = make_record(:message => msg)
|
|
31
|
-
codec.encode_record(rec).
|
|
31
|
+
expect(codec.encode_record(rec)).to match(/#{msg}/)
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
it "should treat messages with invalid encodings as binary data" do
|
|
35
35
|
msg = "HI\u2026".force_encoding("US-ASCII")
|
|
36
36
|
rec = make_record(:message => msg)
|
|
37
|
-
codec.encode_record(rec).
|
|
37
|
+
expect(codec.encode_record(rec)).to match(/HI\\\\xe2\\\\x80\\\\xa6/)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "shouldn't use readable dates by default" do
|
|
41
|
+
expect(codec.iso8601_timestamps?).to eq(false)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "when iso8601_timestamps is set" do
|
|
45
|
+
let(:codec) { Steno::Codec::Json.new( :iso8601_timestamps => true ) }
|
|
46
|
+
|
|
47
|
+
it "should encode timestamps as UTC-formatted strings" do
|
|
48
|
+
allow(record).to receive(:timestamp).and_return 1396473763.811278 # 2014-04-02 22:22:43 +01:00
|
|
49
|
+
parsed = Yajl::Parser.parse(codec.encode_record(record))
|
|
50
|
+
|
|
51
|
+
expect(parsed["timestamp"].class).to eq(String)
|
|
52
|
+
expect(parsed["timestamp"]).to eq("2014-04-02T21:22:43.811278Z")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "should surface the property in a getter" do
|
|
56
|
+
expect(codec.iso8601_timestamps?).to eq(true)
|
|
57
|
+
end
|
|
38
58
|
end
|
|
39
59
|
end
|
|
40
60
|
|
|
@@ -25,7 +25,7 @@ describe Steno::JsonPrettifier do
|
|
|
25
25
|
'--',
|
|
26
26
|
'message', # Log message
|
|
27
27
|
].join("\s+") + "\n"
|
|
28
|
-
prettified.
|
|
28
|
+
expect(prettified).to match(exp_regex)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
it "should always use the largest src len to determine src column width" do
|
|
@@ -60,7 +60,7 @@ describe Steno::JsonPrettifier do
|
|
|
60
60
|
src_col = prettified.match(regex)[1]
|
|
61
61
|
|
|
62
62
|
max_src_len = [max_src_len, src.length].max
|
|
63
|
-
src_col.length.
|
|
63
|
+
expect(src_col.length).to eq(max_src_len)
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
@@ -77,8 +77,8 @@ describe Steno::JsonPrettifier do
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
it "should work with a nil data field" do
|
|
80
|
-
line = prettifier.prettify_line(
|
|
81
|
-
line.
|
|
80
|
+
line = prettifier.prettify_line('{"data":null}')
|
|
81
|
+
expect(line).to include(" - ")
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
data/spec/unit/log_level_spec.rb
CHANGED
|
@@ -5,14 +5,14 @@ describe Steno::LogLevel do
|
|
|
5
5
|
let(:debug_level) { Steno::LogLevel.new(:debug, 1) }
|
|
6
6
|
|
|
7
7
|
it "should be comparable" do
|
|
8
|
-
(info_level > debug_level).
|
|
9
|
-
(debug_level > info_level).
|
|
10
|
-
(info_level == info_level).
|
|
8
|
+
expect(info_level > debug_level).to be_truthy
|
|
9
|
+
expect(debug_level > info_level).to be_falsey
|
|
10
|
+
expect(info_level == info_level).to be_truthy
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
describe "#to_s" do
|
|
14
14
|
it "should return the name of the level" do
|
|
15
|
-
info_level.to_s.
|
|
15
|
+
expect(info_level.to_s).to eq("info")
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
data/spec/unit/logger_spec.rb
CHANGED
|
@@ -6,46 +6,46 @@ describe Steno::Logger do
|
|
|
6
6
|
it "should provide #level, #levelf, and #level? methods for each log level" do
|
|
7
7
|
Steno::Logger::LEVELS.each do |name, _|
|
|
8
8
|
[name, name.to_s + "f", name.to_s + "?"].each do |meth|
|
|
9
|
-
logger.respond_to?(meth).
|
|
9
|
+
expect(logger.respond_to?(meth)).to be_truthy
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
describe "#level_active?" do
|
|
15
15
|
it "should return a boolean indicating if the level is enabled" do
|
|
16
|
-
logger.level_active?(:error).
|
|
17
|
-
logger.level_active?(:info).
|
|
18
|
-
logger.level_active?(:debug).
|
|
16
|
+
expect(logger.level_active?(:error)).to be_truthy
|
|
17
|
+
expect(logger.level_active?(:info)).to be_truthy
|
|
18
|
+
expect(logger.level_active?(:debug)).to be_falsey
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
describe "#<level>?" do
|
|
23
23
|
it "should return a boolean indiciating if <level> is enabled" do
|
|
24
|
-
logger.error
|
|
25
|
-
logger.info
|
|
26
|
-
logger.debug
|
|
24
|
+
expect(logger.error?).to be_truthy
|
|
25
|
+
expect(logger.info?).to be_truthy
|
|
26
|
+
expect(logger.debug?).to be_falsey
|
|
27
27
|
end
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
describe "#level" do
|
|
31
31
|
it "should return the name of the currently active level" do
|
|
32
|
-
logger.level.
|
|
32
|
+
expect(logger.level).to eq(:info)
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
describe "#level=" do
|
|
37
37
|
it "should allow the level to be changed" do
|
|
38
38
|
logger.level = :warn
|
|
39
|
-
logger.level.
|
|
40
|
-
logger.level_active?(:info).
|
|
41
|
-
logger.level_active?(:warn).
|
|
39
|
+
expect(logger.level).to eq(:warn)
|
|
40
|
+
expect(logger.level_active?(:info)).to be_falsey
|
|
41
|
+
expect(logger.level_active?(:warn)).to be_truthy
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
describe "#log" do
|
|
46
46
|
it "should not forward any messages for levels that are inactive" do
|
|
47
47
|
sink = double("sink")
|
|
48
|
-
sink.
|
|
48
|
+
expect(sink).to_not receive(:add_record)
|
|
49
49
|
|
|
50
50
|
my_logger = Steno::Logger.new("test", [sink])
|
|
51
51
|
|
|
@@ -54,7 +54,7 @@ describe Steno::Logger do
|
|
|
54
54
|
|
|
55
55
|
it "should forward messages for levels that are active" do
|
|
56
56
|
sink = double("sink")
|
|
57
|
-
sink.
|
|
57
|
+
expect(sink).to receive(:add_record).with(any_args())
|
|
58
58
|
|
|
59
59
|
my_logger = Steno::Logger.new("test", [sink])
|
|
60
60
|
|
|
@@ -64,19 +64,19 @@ describe Steno::Logger do
|
|
|
64
64
|
it "should not invoke a supplied block if the level is inactive" do
|
|
65
65
|
invoked = false
|
|
66
66
|
logger.debug { invoked = true }
|
|
67
|
-
invoked.
|
|
67
|
+
expect(invoked).to be_falsey
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
it "should invoke a supplied block if the level is active" do
|
|
71
71
|
invoked = false
|
|
72
72
|
logger.warn { invoked = true }
|
|
73
|
-
invoked.
|
|
73
|
+
expect(invoked).to be_truthy
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
it "creates a record with the proper level" do
|
|
77
77
|
sink = double("sink")
|
|
78
|
-
Steno::Record.
|
|
79
|
-
sink.
|
|
78
|
+
expect(Steno::Record).to receive(:new).with("test", :warn, "message", anything, anything).and_call_original
|
|
79
|
+
allow(sink).to receive(:add_record)
|
|
80
80
|
|
|
81
81
|
my_logger = Steno::Logger.new("test", [sink])
|
|
82
82
|
|
|
@@ -86,7 +86,7 @@ describe Steno::Logger do
|
|
|
86
86
|
|
|
87
87
|
describe "#logf" do
|
|
88
88
|
it "should format messages according to the supplied format string" do
|
|
89
|
-
logger.
|
|
89
|
+
expect(logger).to receive(:log).with(:debug, "test 1 2.20")
|
|
90
90
|
logger.debugf("test %d %0.2f", 1, 2.2)
|
|
91
91
|
end
|
|
92
92
|
end
|
|
@@ -94,8 +94,8 @@ describe Steno::Logger do
|
|
|
94
94
|
describe "#tag" do
|
|
95
95
|
it "should return a tagged logger" do
|
|
96
96
|
tagged_logger = logger.tag("foo" => "bar")
|
|
97
|
-
tagged_logger.
|
|
98
|
-
tagged_logger.user_data.
|
|
97
|
+
expect(tagged_logger).to_not be_nil
|
|
98
|
+
expect(tagged_logger.user_data).to eq({ "foo" => "bar" })
|
|
99
99
|
end
|
|
100
100
|
end
|
|
101
101
|
end
|
data/spec/unit/record_spec.rb
CHANGED
|
@@ -5,26 +5,26 @@ describe Steno::Record do
|
|
|
5
5
|
let(:record) { Steno::Record.new("test", :info, message) }
|
|
6
6
|
|
|
7
7
|
it "should set the process id" do
|
|
8
|
-
record.process_id.
|
|
8
|
+
expect(record.process_id).to eq(Process.pid)
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
it "should set the thread id" do
|
|
12
|
-
record.thread_id.
|
|
12
|
+
expect(record.thread_id).to eq(Thread.current.object_id)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "should set the fiber id(if available)", :needs_fibers => true do
|
|
16
|
-
record.fiber_id.
|
|
16
|
+
expect(record.fiber_id).to eq(Fiber.current.object_id)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
it "should set the source" do
|
|
20
|
-
record.source.
|
|
20
|
+
expect(record.source).to eq("test")
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
it "should stringify the message" do
|
|
24
|
-
record.message.
|
|
24
|
+
expect(record.message).to be_a(String)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "should use a UTC timestamp" do
|
|
28
|
-
record.timestamp.to_f.
|
|
28
|
+
expect(record.timestamp.to_f).to be_within(0.1).of(Time.now.utc.to_f)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
@@ -11,20 +11,20 @@ describe Steno::Sink::IO do
|
|
|
11
11
|
|
|
12
12
|
describe "#initialize" do
|
|
13
13
|
it "should initialize FluentLogger with the default option" do
|
|
14
|
-
Fluent::Logger::FluentLogger.
|
|
14
|
+
expect(Fluent::Logger::FluentLogger).to receive(:new).with("steno", {
|
|
15
15
|
:host => "127.0.0.1",
|
|
16
16
|
:port => 24224,
|
|
17
17
|
:buffer_limit => Fluent::Logger::FluentLogger::BUFFER_LIMIT,
|
|
18
|
-
}).and_return()
|
|
18
|
+
}).and_return(nil)
|
|
19
19
|
sink = Steno::Sink::Fluentd.new()
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
it "should initialize FliuentLogger with override options" do
|
|
23
|
-
Fluent::Logger::FluentLogger.
|
|
23
|
+
expect(Fluent::Logger::FluentLogger).to receive(:new).with("vcap", {
|
|
24
24
|
:host => "localhost",
|
|
25
25
|
:port => 8080,
|
|
26
26
|
:buffer_limit => 1024,
|
|
27
|
-
}).and_return()
|
|
27
|
+
}).and_return(nil)
|
|
28
28
|
sink = Steno::Sink::Fluentd.new({
|
|
29
29
|
:tag_prefix => "vcap",
|
|
30
30
|
:host => "localhost",
|
|
@@ -37,10 +37,10 @@ describe Steno::Sink::IO do
|
|
|
37
37
|
describe "#add_record" do
|
|
38
38
|
it "should post an record with the correct tag" do
|
|
39
39
|
fluentd = double("fluentd")
|
|
40
|
-
Fluent::Logger::FluentLogger.
|
|
41
|
-
fluentd.
|
|
40
|
+
expect(Fluent::Logger::FluentLogger).to receive(:new).and_return(fluentd)
|
|
41
|
+
expect(fluentd).to receive(:post).with("source", record)
|
|
42
42
|
sink = Steno::Sink::Fluentd.new()
|
|
43
43
|
sink.add_record(record)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
|
-
end
|
|
46
|
+
end
|
data/spec/unit/sink/io_spec.rb
CHANGED
|
@@ -13,55 +13,55 @@ describe Steno::Sink::IO do
|
|
|
13
13
|
it "should return a new sink configured to append to the file at path with autosync set to true by default" do
|
|
14
14
|
mock_handle = double("file handle")
|
|
15
15
|
|
|
16
|
-
File.
|
|
17
|
-
mock_handle.
|
|
16
|
+
expect(File).to receive(:open).with("path", "a+").and_return(mock_handle)
|
|
17
|
+
expect(mock_handle).to receive(:sync=).with(true)
|
|
18
18
|
|
|
19
19
|
mock_sink = double("sink")
|
|
20
|
-
Steno::Sink::IO.
|
|
20
|
+
expect(Steno::Sink::IO).to receive(:new).with(mock_handle,
|
|
21
21
|
:max_retries => 10).
|
|
22
22
|
and_return(mock_sink)
|
|
23
23
|
|
|
24
24
|
returned = Steno::Sink::IO.for_file("path",
|
|
25
25
|
:max_retries => 10)
|
|
26
|
-
returned.
|
|
26
|
+
expect(returned).to eq(mock_sink)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
it "should return a new sink configured to append to the file at path with specified options" do
|
|
30
30
|
mock_handle = double("file handle")
|
|
31
31
|
|
|
32
|
-
File.
|
|
33
|
-
mock_handle.
|
|
32
|
+
expect(File).to receive(:open).with("path", "a+").and_return(mock_handle)
|
|
33
|
+
expect(mock_handle).to receive(:sync=).with(false)
|
|
34
34
|
|
|
35
35
|
mock_sink = double("sink")
|
|
36
|
-
Steno::Sink::IO.
|
|
36
|
+
expect(Steno::Sink::IO).to receive(:new).with(mock_handle,
|
|
37
37
|
:max_retries => 10).
|
|
38
38
|
and_return(mock_sink)
|
|
39
39
|
|
|
40
40
|
returned = Steno::Sink::IO.for_file("path",
|
|
41
41
|
:autoflush => false,
|
|
42
42
|
:max_retries => 10)
|
|
43
|
-
returned.
|
|
43
|
+
expect(returned).to eq(mock_sink)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
describe "#add_record" do
|
|
48
48
|
it "should encode the record and write it to the underlying io object" do
|
|
49
49
|
codec = double("codec")
|
|
50
|
-
codec.
|
|
50
|
+
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
|
51
51
|
|
|
52
52
|
io = double("io")
|
|
53
|
-
io.
|
|
53
|
+
expect(io).to receive(:write).with(record.message)
|
|
54
54
|
|
|
55
55
|
Steno::Sink::IO.new(io, :codec => codec).add_record(record)
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
it "should by default not retry on IOError" do
|
|
59
59
|
codec = double("codec")
|
|
60
|
-
codec.
|
|
60
|
+
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
|
61
61
|
|
|
62
62
|
io = double("io")
|
|
63
63
|
|
|
64
|
-
io.
|
|
64
|
+
expect(io).to receive(:write).with(record.message).ordered.and_raise(IOError)
|
|
65
65
|
|
|
66
66
|
expect do
|
|
67
67
|
Steno::Sink::IO.new(io, :codec => codec).add_record(record)
|
|
@@ -70,11 +70,11 @@ describe Steno::Sink::IO do
|
|
|
70
70
|
|
|
71
71
|
it "should retry not more than specified number of times on IOError" do
|
|
72
72
|
codec = double("codec")
|
|
73
|
-
codec.
|
|
73
|
+
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
|
74
74
|
|
|
75
75
|
io = double("io")
|
|
76
76
|
|
|
77
|
-
io.
|
|
77
|
+
expect(io).to receive(:write).exactly(3).times.with(record.message).
|
|
78
78
|
and_raise(IOError)
|
|
79
79
|
|
|
80
80
|
expect do
|
|
@@ -85,25 +85,25 @@ describe Steno::Sink::IO do
|
|
|
85
85
|
|
|
86
86
|
it "should retry on IOError and succeed" do
|
|
87
87
|
codec = double("codec")
|
|
88
|
-
codec.
|
|
88
|
+
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
|
89
89
|
|
|
90
90
|
io = double("io")
|
|
91
|
-
io.
|
|
91
|
+
expect(io).to receive(:write).with(record.message).once.
|
|
92
92
|
and_raise(IOError)
|
|
93
|
-
io.
|
|
93
|
+
expect(io).to receive(:write).with(record.message).once.ordered.
|
|
94
94
|
and_return(record.message)
|
|
95
95
|
|
|
96
96
|
expect do
|
|
97
97
|
Steno::Sink::IO.new(io, :codec => codec, :max_retries => 1).
|
|
98
98
|
add_record(record)
|
|
99
|
-
end.to_not raise_error
|
|
99
|
+
end.to_not raise_error
|
|
100
100
|
end
|
|
101
101
|
end
|
|
102
102
|
|
|
103
103
|
describe "#flush" do
|
|
104
104
|
it "should call flush on the underlying io object" do
|
|
105
105
|
io = double("io")
|
|
106
|
-
io.
|
|
106
|
+
expect(io).to receive(:flush)
|
|
107
107
|
|
|
108
108
|
Steno::Sink::IO.new(io).flush
|
|
109
109
|
end
|
|
@@ -11,26 +11,28 @@ unless Steno::Sink::WINDOWS
|
|
|
11
11
|
|
|
12
12
|
let(:record_with_big_message) do
|
|
13
13
|
Steno::Record.new("source", level.name,
|
|
14
|
-
|
|
14
|
+
"a" * (Steno::Sink::Syslog::MAX_MESSAGE_SIZE + 1))
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
describe "#add_record" do
|
|
18
|
+
after do
|
|
19
|
+
Syslog::Logger.syslog = nil
|
|
20
|
+
end
|
|
21
|
+
|
|
18
22
|
it "should append an encoded record with the correct priority" do
|
|
19
23
|
identity = "test"
|
|
20
24
|
|
|
21
|
-
syslog = double("syslog")
|
|
22
|
-
Syslog.
|
|
23
|
-
.with(identity, Syslog::LOG_PID, Syslog::LOG_USER) \
|
|
24
|
-
.and_return(syslog)
|
|
25
|
+
syslog = double("syslog", facility: nil)
|
|
26
|
+
expect(Syslog).to receive(:open).and_return(syslog)
|
|
25
27
|
|
|
26
28
|
sink = Steno::Sink::Syslog.instance
|
|
27
29
|
sink.open(identity)
|
|
28
30
|
|
|
29
31
|
codec = double("codec")
|
|
30
|
-
codec.
|
|
32
|
+
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
|
31
33
|
sink.codec = codec
|
|
32
34
|
|
|
33
|
-
syslog.
|
|
35
|
+
expect(syslog).to receive(:log).with(Syslog::LOG_INFO, "%s", record.message)
|
|
34
36
|
|
|
35
37
|
sink.add_record(record)
|
|
36
38
|
end
|
|
@@ -38,10 +40,8 @@ unless Steno::Sink::WINDOWS
|
|
|
38
40
|
it "should truncate the record message if its greater than than allowed size" do
|
|
39
41
|
identity = "test"
|
|
40
42
|
|
|
41
|
-
syslog = double("syslog")
|
|
42
|
-
Syslog.
|
|
43
|
-
.with(identity, Syslog::LOG_PID, Syslog::LOG_USER) \
|
|
44
|
-
.and_return(syslog)
|
|
43
|
+
syslog = double("syslog", facility: nil)
|
|
44
|
+
expect(Syslog).to receive(:open).and_return(syslog)
|
|
45
45
|
|
|
46
46
|
sink = Steno::Sink::Syslog.instance
|
|
47
47
|
sink.open(identity)
|
|
@@ -50,17 +50,17 @@ unless Steno::Sink::WINDOWS
|
|
|
50
50
|
slice(0..(Steno::Sink::Syslog::MAX_MESSAGE_SIZE) - 4)
|
|
51
51
|
truncated << Steno::Sink::Syslog::TRUNCATE_POSTFIX
|
|
52
52
|
codec = double("codec")
|
|
53
|
-
codec.
|
|
54
|
-
args.size.
|
|
55
|
-
args[0].message.
|
|
56
|
-
args[0].message.size.
|
|
53
|
+
expect(codec).to receive(:encode_record) do |*args|
|
|
54
|
+
expect(args.size).to eq(1)
|
|
55
|
+
expect(args[0].message).to eq(truncated)
|
|
56
|
+
expect(args[0].message.size).to be <= Steno::Sink::Syslog::MAX_MESSAGE_SIZE
|
|
57
57
|
|
|
58
58
|
next args[0].message
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
sink.codec = codec
|
|
62
62
|
|
|
63
|
-
syslog.
|
|
63
|
+
expect(syslog).to receive(:log).with(Syslog::LOG_INFO, "%s", truncated)
|
|
64
64
|
|
|
65
65
|
sink.add_record(record_with_big_message)
|
|
66
66
|
end
|
data/spec/unit/steno_spec.rb
CHANGED
|
@@ -10,15 +10,15 @@ describe Steno do
|
|
|
10
10
|
describe "#logger" do
|
|
11
11
|
it "should return a new Steno::Logger instance" do
|
|
12
12
|
logger = Steno.logger("test")
|
|
13
|
-
logger.
|
|
14
|
-
logger.name.
|
|
13
|
+
expect(logger).to_not be_nil
|
|
14
|
+
expect(logger.name).to eq("test")
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it "should memoize loggers by name" do
|
|
18
18
|
logger1 = Steno.logger("test")
|
|
19
19
|
logger2 = Steno.logger("test")
|
|
20
20
|
|
|
21
|
-
logger1.object_id.
|
|
21
|
+
expect(logger1.object_id).to eq(logger2.object_id)
|
|
22
22
|
end
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -26,28 +26,28 @@ describe Steno do
|
|
|
26
26
|
it "should modify the levels of existing loggers that match the regex" do
|
|
27
27
|
logger = Steno.logger("test")
|
|
28
28
|
|
|
29
|
-
logger.level.
|
|
29
|
+
expect(logger.level).to eq(:info)
|
|
30
30
|
|
|
31
31
|
Steno.set_logger_regexp(/te/, :debug)
|
|
32
32
|
|
|
33
|
-
logger.level.
|
|
33
|
+
expect(logger.level).to eq(:debug)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
it "should modify the levels of new loggers after a regexp has been set" do
|
|
37
37
|
Steno.set_logger_regexp(/te/, :debug)
|
|
38
38
|
|
|
39
|
-
Steno.logger("te").level.
|
|
39
|
+
expect(Steno.logger("te").level).to eq(:debug)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
it "should reset the levels of previously matching loggers when changed" do
|
|
43
43
|
Steno.set_logger_regexp(/foo/, :debug)
|
|
44
44
|
|
|
45
45
|
logger = Steno.logger("foo")
|
|
46
|
-
logger.level.
|
|
46
|
+
expect(logger.level).to eq(:debug)
|
|
47
47
|
|
|
48
48
|
Steno.set_logger_regexp(/bar/, :debug)
|
|
49
49
|
|
|
50
|
-
logger.level.
|
|
50
|
+
expect(logger.level).to eq(:info)
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
@@ -56,12 +56,12 @@ describe Steno do
|
|
|
56
56
|
Steno.set_logger_regexp(/te/, :debug)
|
|
57
57
|
|
|
58
58
|
logger = Steno.logger("test")
|
|
59
|
-
logger.level.
|
|
59
|
+
expect(logger.level).to eq(:debug)
|
|
60
60
|
|
|
61
61
|
Steno.clear_logger_regexp
|
|
62
62
|
|
|
63
|
-
logger.level.
|
|
64
|
-
Steno.logger_regexp.
|
|
63
|
+
expect(logger.level).to eq(:info)
|
|
64
|
+
expect(Steno.logger_regexp).to be_nil
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
@@ -80,7 +80,7 @@ describe Steno do
|
|
|
80
80
|
loggers.last.level = level
|
|
81
81
|
end
|
|
82
82
|
|
|
83
|
-
Steno.logger_level_snapshot.
|
|
83
|
+
expect(Steno.logger_level_snapshot).to eq(expected)
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
1
3
|
describe Steno::TaggedLogger do
|
|
2
4
|
let(:sink) { NullSink.new }
|
|
3
5
|
let(:logger) { Steno::Logger.new("test", [sink]) }
|
|
@@ -6,28 +8,28 @@ describe Steno::TaggedLogger do
|
|
|
6
8
|
|
|
7
9
|
it "should add any user data to each log record" do
|
|
8
10
|
tagged_logger.info("testing", "test" => "data")
|
|
9
|
-
sink.records.size.
|
|
10
|
-
sink.records[0].data.
|
|
11
|
+
expect(sink.records.size).to eq(1)
|
|
12
|
+
expect(sink.records[0].data).to eq(user_data.merge("test" => "data"))
|
|
11
13
|
|
|
12
14
|
tagged_logger.log_exception(RuntimeError.new("hi"))
|
|
13
|
-
sink.records.size.
|
|
14
|
-
sink.records[1].data.
|
|
15
|
+
expect(sink.records.size).to eq(2)
|
|
16
|
+
expect(sink.records[1].data).to eq(user_data.merge(:backtrace => nil))
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
it "should forward missing methods to the proxied logger" do
|
|
18
|
-
tagged_logger.level.
|
|
20
|
+
expect(tagged_logger.level).to eq(:info)
|
|
19
21
|
tagged_logger.level = :warn
|
|
20
22
|
|
|
21
|
-
logger.level.
|
|
23
|
+
expect(logger.level).to eq(:warn)
|
|
22
24
|
|
|
23
|
-
tagged_logger.level_active?(:info).
|
|
25
|
+
expect(tagged_logger.level_active?(:info)).to be_falsey
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
describe "#tag" do
|
|
27
29
|
it "should return a new tagged logger with merged user-data" do
|
|
28
30
|
tl = tagged_logger.tag("bar" => "baz")
|
|
29
|
-
tl.proxied_logger.
|
|
30
|
-
tl.user_data.
|
|
31
|
+
expect(tl.proxied_logger).to eq(logger)
|
|
32
|
+
expect(tl.user_data).to eq(user_data.merge("bar" => "baz"))
|
|
31
33
|
end
|
|
32
34
|
end
|
|
33
35
|
end
|
data/steno.gemspec
CHANGED
|
@@ -28,10 +28,9 @@ Gem::Specification.new do |gem|
|
|
|
28
28
|
gem.add_dependency("yajl-ruby", "~> 1.0")
|
|
29
29
|
gem.add_dependency("fluent-logger")
|
|
30
30
|
|
|
31
|
-
gem.add_development_dependency("ci_reporter")
|
|
32
31
|
gem.add_development_dependency("rack-test")
|
|
33
32
|
gem.add_development_dependency("rake")
|
|
34
|
-
gem.add_development_dependency("rspec")
|
|
33
|
+
gem.add_development_dependency("rspec", "~>3.4.0")
|
|
35
34
|
|
|
36
35
|
if RUBY_PLATFORM=~ /mswin|mingw|cygwin/
|
|
37
36
|
gem.platform = Gem::Platform::CURRENT
|
metadata
CHANGED
|
@@ -1,99 +1,85 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: steno
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- mpage
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: yajl-ruby
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - ~>
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '1.0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - ~>
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '1.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: fluent-logger
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- -
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- -
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: ci_reporter
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ! '>='
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :development
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ! '>='
|
|
38
|
+
- - ">="
|
|
53
39
|
- !ruby/object:Gem::Version
|
|
54
40
|
version: '0'
|
|
55
41
|
- !ruby/object:Gem::Dependency
|
|
56
42
|
name: rack-test
|
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
|
58
44
|
requirements:
|
|
59
|
-
- -
|
|
45
|
+
- - ">="
|
|
60
46
|
- !ruby/object:Gem::Version
|
|
61
47
|
version: '0'
|
|
62
48
|
type: :development
|
|
63
49
|
prerelease: false
|
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
51
|
requirements:
|
|
66
|
-
- -
|
|
52
|
+
- - ">="
|
|
67
53
|
- !ruby/object:Gem::Version
|
|
68
54
|
version: '0'
|
|
69
55
|
- !ruby/object:Gem::Dependency
|
|
70
56
|
name: rake
|
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
|
72
58
|
requirements:
|
|
73
|
-
- -
|
|
59
|
+
- - ">="
|
|
74
60
|
- !ruby/object:Gem::Version
|
|
75
61
|
version: '0'
|
|
76
62
|
type: :development
|
|
77
63
|
prerelease: false
|
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
65
|
requirements:
|
|
80
|
-
- -
|
|
66
|
+
- - ">="
|
|
81
67
|
- !ruby/object:Gem::Version
|
|
82
68
|
version: '0'
|
|
83
69
|
- !ruby/object:Gem::Dependency
|
|
84
70
|
name: rspec
|
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
|
86
72
|
requirements:
|
|
87
|
-
- -
|
|
73
|
+
- - "~>"
|
|
88
74
|
- !ruby/object:Gem::Version
|
|
89
|
-
version:
|
|
75
|
+
version: 3.4.0
|
|
90
76
|
type: :development
|
|
91
77
|
prerelease: false
|
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
79
|
requirements:
|
|
94
|
-
- -
|
|
80
|
+
- - "~>"
|
|
95
81
|
- !ruby/object:Gem::Version
|
|
96
|
-
version:
|
|
82
|
+
version: 3.4.0
|
|
97
83
|
description: A thread-safe logging library designed to support multiple log destinations.
|
|
98
84
|
email:
|
|
99
85
|
- mpage@rbcon.com
|
|
@@ -156,17 +142,17 @@ require_paths:
|
|
|
156
142
|
- lib
|
|
157
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
144
|
requirements:
|
|
159
|
-
- -
|
|
145
|
+
- - ">="
|
|
160
146
|
- !ruby/object:Gem::Version
|
|
161
147
|
version: '0'
|
|
162
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
149
|
requirements:
|
|
164
|
-
- -
|
|
150
|
+
- - ">="
|
|
165
151
|
- !ruby/object:Gem::Version
|
|
166
152
|
version: '0'
|
|
167
153
|
requirements: []
|
|
168
154
|
rubyforge_project:
|
|
169
|
-
rubygems_version: 2.
|
|
155
|
+
rubygems_version: 2.4.5.1
|
|
170
156
|
signing_key:
|
|
171
157
|
specification_version: 4
|
|
172
158
|
summary: A logging library.
|