steno 1.3.4 → 1.3.5
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 -5
- data/NOTICE +14 -0
- data/Rakefile +6 -7
- data/bin/steno-prettify +24 -25
- data/lib/steno/codec/base.rb +1 -1
- data/lib/steno/codec/json.rb +16 -19
- data/lib/steno/codec.rb +2 -2
- data/lib/steno/config.rb +22 -33
- data/lib/steno/context.rb +3 -3
- data/lib/steno/json_prettifier.rb +30 -29
- data/lib/steno/log_level.rb +1 -2
- data/lib/steno/logger.rb +22 -26
- data/lib/steno/record.rb +5 -15
- data/lib/steno/sink/base.rb +2 -3
- data/lib/steno/sink/counter.rb +4 -8
- data/lib/steno/sink/eventlog.rb +16 -17
- data/lib/steno/sink/fluentd.rb +4 -5
- data/lib/steno/sink/io.rb +8 -12
- data/lib/steno/sink/syslog.rb +15 -13
- data/lib/steno/sink.rb +6 -6
- data/lib/steno/tagged_logger.rb +2 -3
- data/lib/steno/version.rb +1 -1
- data/lib/steno.rb +16 -21
- data/spec/spec_helper.rb +4 -4
- data/spec/support/barrier.rb +2 -2
- data/spec/support/shared_context_specs.rb +4 -4
- data/spec/unit/config_spec.rb +87 -94
- data/spec/unit/context_spec.rb +17 -17
- data/spec/unit/core_ext_spec.rb +11 -11
- data/spec/unit/json_codec_spec.rb +26 -26
- data/spec/unit/json_prettifier_spec.rb +22 -22
- data/spec/unit/log_level_spec.rb +5 -6
- data/spec/unit/logger_spec.rb +39 -39
- data/spec/unit/record_spec.rb +10 -10
- data/spec/unit/sink/counter_spec.rb +7 -7
- data/spec/unit/sink/eventlog_spec.rb +14 -15
- data/spec/unit/sink/fluentd_spec.rb +26 -26
- data/spec/unit/sink/io_spec.rb +49 -49
- data/spec/unit/sink/syslog_spec.rb +43 -19
- data/spec/unit/steno_spec.rb +24 -24
- data/spec/unit/tagged_logger_spec.rb +12 -12
- data/steno.gemspec +28 -27
- metadata +61 -38
data/spec/unit/config_spec.rb
CHANGED
@@ -1,29 +1,28 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'fileutils'
|
2
|
+
require 'yaml'
|
3
3
|
|
4
|
-
require
|
4
|
+
require 'spec_helper'
|
5
5
|
|
6
6
|
describe Steno::Config do
|
7
|
-
|
8
7
|
if Steno::Sink::WINDOWS
|
9
|
-
describe
|
10
|
-
before
|
11
|
-
@log_path =
|
8
|
+
describe '.from_hash' do
|
9
|
+
before do
|
10
|
+
@log_path = 'some_file'
|
12
11
|
|
13
|
-
@mock_sink_file = double(
|
12
|
+
@mock_sink_file = double('sink')
|
14
13
|
expect(@mock_sink_file).to receive(:codec=)
|
15
14
|
expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
|
16
|
-
|
17
|
-
|
15
|
+
max_retries: 5)
|
16
|
+
.and_return(@mock_sink_file)
|
18
17
|
|
19
|
-
@mock_sink_eventlog = double(
|
18
|
+
@mock_sink_eventlog = double('sink')
|
20
19
|
expect(@mock_sink_eventlog).to receive(:codec=)
|
21
|
-
expect(@mock_sink_eventlog).to receive(:open).with(
|
22
|
-
expect(Steno::Sink::Eventlog).to receive(:instance).twice
|
23
|
-
|
20
|
+
expect(@mock_sink_eventlog).to receive(:open).with('test')
|
21
|
+
expect(Steno::Sink::Eventlog).to receive(:instance).twice
|
22
|
+
.and_return(@mock_sink_eventlog)
|
24
23
|
end
|
25
24
|
|
26
|
-
after
|
25
|
+
after do
|
27
26
|
@config = Steno::Config.from_hash(@hash)
|
28
27
|
|
29
28
|
expect(@config.default_log_level).to eq(:debug2)
|
@@ -31,49 +30,48 @@ describe Steno::Config do
|
|
31
30
|
expect(@config.codec.class).to eq(Steno::Codec::Json)
|
32
31
|
|
33
32
|
expect(@config.sinks.size).to eq(2)
|
34
|
-
expect(@config.sinks).to
|
33
|
+
expect(@config.sinks).to contain_exactly(@mock_sink_file, @mock_sink_eventlog)
|
35
34
|
end
|
36
35
|
|
37
|
-
it
|
36
|
+
it 'works for symbolized keys' do
|
38
37
|
@hash = {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
file: @log_path,
|
39
|
+
level: 'debug2',
|
40
|
+
default_log_level: 'warn',
|
41
|
+
eventlog: 'test',
|
42
|
+
max_retries: 5
|
44
43
|
}
|
45
44
|
end
|
46
45
|
|
47
|
-
it
|
46
|
+
it 'works for non-symbolized keys' do
|
48
47
|
@hash = {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
'file' => @log_path,
|
49
|
+
'level' => 'debug2',
|
50
|
+
'default_log_level' => 'warn',
|
51
|
+
'eventlog' => 'test',
|
52
|
+
'max_retries' => 5
|
54
53
|
}
|
55
54
|
end
|
56
|
-
|
57
55
|
end
|
58
56
|
else
|
59
|
-
describe
|
60
|
-
before
|
61
|
-
@log_path =
|
57
|
+
describe '.from_hash' do
|
58
|
+
before do
|
59
|
+
@log_path = 'some_file'
|
62
60
|
|
63
|
-
@mock_sink_file = double(
|
61
|
+
@mock_sink_file = double('sink')
|
64
62
|
allow(@mock_sink_file).to receive(:codec=)
|
65
63
|
expect(Steno::Sink::IO).to receive(:for_file).with(@log_path,
|
66
|
-
|
67
|
-
|
64
|
+
max_retries: 5)
|
65
|
+
.and_return(@mock_sink_file)
|
68
66
|
|
69
|
-
@mock_sink_syslog = double(
|
67
|
+
@mock_sink_syslog = double('sink')
|
70
68
|
expect(@mock_sink_syslog).to receive(:codec=)
|
71
|
-
expect(@mock_sink_syslog).to receive(:open).with(
|
72
|
-
expect(Steno::Sink::Syslog).to receive(:instance).twice
|
73
|
-
|
69
|
+
expect(@mock_sink_syslog).to receive(:open).with('test')
|
70
|
+
expect(Steno::Sink::Syslog).to receive(:instance).twice
|
71
|
+
.and_return(@mock_sink_syslog)
|
74
72
|
end
|
75
73
|
|
76
|
-
after
|
74
|
+
after do
|
77
75
|
@config = Steno::Config.from_hash(@hash)
|
78
76
|
|
79
77
|
expect(@config.default_log_level).to eq(:debug2)
|
@@ -81,44 +79,43 @@ describe Steno::Config do
|
|
81
79
|
expect(@config.codec.class).to eq(Steno::Codec::Json)
|
82
80
|
|
83
81
|
expect(@config.sinks.size).to eq(2)
|
84
|
-
expect(@config.sinks).to
|
82
|
+
expect(@config.sinks).to contain_exactly(@mock_sink_file, @mock_sink_syslog)
|
85
83
|
end
|
86
84
|
|
87
|
-
it
|
85
|
+
it 'works for symbolized keys' do
|
88
86
|
@hash = {
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
file: @log_path,
|
88
|
+
level: 'debug2',
|
89
|
+
default_log_level: 'warn',
|
90
|
+
syslog: 'test',
|
91
|
+
max_retries: 5
|
94
92
|
}
|
95
93
|
end
|
96
94
|
|
97
|
-
it
|
95
|
+
it 'works for non-symbolized keys' do
|
98
96
|
@hash = {
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
97
|
+
'file' => @log_path,
|
98
|
+
'level' => 'debug2',
|
99
|
+
'default_log_level' => 'warn',
|
100
|
+
'syslog' => 'test',
|
101
|
+
'max_retries' => 5
|
104
102
|
}
|
105
103
|
end
|
106
|
-
|
107
104
|
end
|
108
105
|
end
|
109
106
|
|
110
|
-
describe
|
111
|
-
before
|
107
|
+
describe '.from_file' do
|
108
|
+
before do
|
112
109
|
@tmpdir = Dir.mktmpdir
|
113
|
-
@config_path = File.join(@tmpdir,
|
114
|
-
@log_path = File.join(@tmpdir,
|
110
|
+
@config_path = File.join(@tmpdir, 'config.yml')
|
111
|
+
@log_path = File.join(@tmpdir, 'test.log')
|
115
112
|
end
|
116
113
|
|
117
|
-
after
|
114
|
+
after do
|
118
115
|
FileUtils.rm_rf(@tmpdir)
|
119
116
|
end
|
120
117
|
|
121
|
-
it
|
118
|
+
it 'returns Steno::Config instance with sane defaults' do
|
122
119
|
write_config(@config_path, {})
|
123
120
|
|
124
121
|
config = Steno::Config.from_file(@config_path)
|
@@ -134,60 +131,60 @@ describe Steno::Config do
|
|
134
131
|
expect(config.codec.iso8601_timestamps?).to eq(false)
|
135
132
|
end
|
136
133
|
|
137
|
-
it
|
138
|
-
write_config(@config_path, {
|
134
|
+
it 'configures json codec with readable dates if iso8601_timestamps is true' do
|
135
|
+
write_config(@config_path, { 'iso8601_timestamps' => 'true' })
|
139
136
|
config = Steno::Config.from_file(@config_path)
|
140
137
|
expect(config.codec.class).to eq(Steno::Codec::Json)
|
141
138
|
expect(config.codec.iso8601_timestamps?).to eq(true)
|
142
139
|
end
|
143
140
|
|
144
|
-
it
|
145
|
-
write_config(@config_path, {
|
141
|
+
it 'sets the default_log_level if a key with the same name is supplied' do
|
142
|
+
write_config(@config_path, { 'level' => 'debug2' })
|
146
143
|
expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
|
147
144
|
|
148
|
-
write_config(@config_path, {
|
145
|
+
write_config(@config_path, { 'default_log_level' => 'debug2' })
|
149
146
|
expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
|
150
147
|
end
|
151
148
|
|
152
|
-
it "
|
153
|
-
write_config(@config_path, {
|
154
|
-
|
149
|
+
it "reads the 'level' key if both default_log_level and level are spscified" do
|
150
|
+
write_config(@config_path, { 'level' => 'debug2',
|
151
|
+
'default_log_level' => 'warn' })
|
155
152
|
expect(Steno::Config.from_file(@config_path).default_log_level).to eq(:debug2)
|
156
153
|
end
|
157
154
|
|
158
|
-
it "
|
159
|
-
write_config(@config_path, {
|
160
|
-
mock_sink = double(
|
155
|
+
it "adds a file sink if the 'file' key is specified" do
|
156
|
+
write_config(@config_path, { 'file' => @log_path, 'max_retries' => 2 })
|
157
|
+
mock_sink = double('sink')
|
161
158
|
expect(mock_sink).to receive(:codec=)
|
162
159
|
|
163
|
-
expect(Steno::Sink::IO).to receive(:for_file)
|
164
|
-
|
160
|
+
expect(Steno::Sink::IO).to receive(:for_file)
|
161
|
+
.with(@log_path, max_retries: 2).and_return(mock_sink)
|
165
162
|
config = Steno::Config.from_file(@config_path)
|
166
163
|
expect(config.sinks.size).to eq(1)
|
167
164
|
expect(config.sinks[0]).to eq(mock_sink)
|
168
165
|
end
|
169
166
|
|
170
167
|
if Steno::Sink::WINDOWS
|
171
|
-
it "
|
172
|
-
write_config(@config_path, {
|
173
|
-
mock_sink = double(
|
174
|
-
expect(mock_sink).to receive(:open).with(
|
168
|
+
it "adds a event sink if the 'eventlog' key is specified" do
|
169
|
+
write_config(@config_path, { 'eventlog' => 'test' })
|
170
|
+
mock_sink = double('sink')
|
171
|
+
expect(mock_sink).to receive(:open).with('test')
|
175
172
|
expect(mock_sink).to receive(:codec=)
|
176
173
|
|
177
|
-
expect(Steno::Sink::Eventlog).to receive(:instance).twice
|
174
|
+
expect(Steno::Sink::Eventlog).to receive(:instance).twice.and_return(mock_sink)
|
178
175
|
|
179
176
|
config = Steno::Config.from_file(@config_path)
|
180
177
|
expect(config.sinks.size).to eq(1)
|
181
178
|
expect(config.sinks[0]).to eq(mock_sink)
|
182
179
|
end
|
183
180
|
else
|
184
|
-
it "
|
185
|
-
write_config(@config_path, {
|
186
|
-
mock_sink = double(
|
187
|
-
expect(mock_sink).to receive(:open).with(
|
181
|
+
it "adds a syslog sink if the 'syslog' key is specified" do
|
182
|
+
write_config(@config_path, { 'syslog' => 'test' })
|
183
|
+
mock_sink = double('sink')
|
184
|
+
expect(mock_sink).to receive(:open).with('test')
|
188
185
|
expect(mock_sink).to receive(:codec=)
|
189
186
|
|
190
|
-
expect(Steno::Sink::Syslog).to receive(:instance).twice
|
187
|
+
expect(Steno::Sink::Syslog).to receive(:instance).twice.and_return(mock_sink)
|
191
188
|
|
192
189
|
config = Steno::Config.from_file(@config_path)
|
193
190
|
expect(config.sinks.size).to eq(1)
|
@@ -195,11 +192,9 @@ describe Steno::Config do
|
|
195
192
|
end
|
196
193
|
end
|
197
194
|
|
198
|
-
|
199
|
-
|
200
|
-
it "should add an io sink to stdout if no sinks are explicitly specified in the config file" do
|
195
|
+
it 'adds an io sink to stdout if no sinks are explicitly specified in the config file' do
|
201
196
|
write_config(@config_path, {})
|
202
|
-
mock_sink = double(
|
197
|
+
mock_sink = double('sink')
|
203
198
|
expect(mock_sink).to receive(:codec=)
|
204
199
|
|
205
200
|
expect(Steno::Sink::IO).to receive(:new).with(STDOUT).and_return(mock_sink)
|
@@ -209,21 +204,19 @@ describe Steno::Config do
|
|
209
204
|
expect(config.sinks[0]).to eq(mock_sink)
|
210
205
|
end
|
211
206
|
|
212
|
-
it
|
213
|
-
write_config(@config_path, {
|
207
|
+
it 'merges supplied overrides with the file based config' do
|
208
|
+
write_config(@config_path, { 'default_log_level' => 'debug' })
|
214
209
|
|
215
210
|
context = Steno::Context::ThreadLocal.new
|
216
211
|
config = Steno::Config.from_file(@config_path,
|
217
|
-
:
|
218
|
-
:
|
212
|
+
default_log_level: 'warn',
|
213
|
+
context: context)
|
219
214
|
expect(config.context).to eq(context)
|
220
215
|
expect(config.default_log_level).to eq(:warn)
|
221
216
|
end
|
222
217
|
end
|
223
218
|
|
224
219
|
def write_config(path, config)
|
225
|
-
File.
|
226
|
-
f.write(YAML.dump({"logging" => config}))
|
227
|
-
end
|
220
|
+
File.write(path, YAML.dump({ 'logging' => config }))
|
228
221
|
end
|
229
222
|
end
|
data/spec/unit/context_spec.rb
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Context::Null do
|
4
|
-
include_context
|
4
|
+
include_context 'steno context'
|
5
5
|
|
6
6
|
let(:context) { Steno::Context::Null.new }
|
7
7
|
|
8
|
-
it
|
8
|
+
it 'stores no data' do
|
9
9
|
expect(context.data).to eq({})
|
10
|
-
context.data[
|
10
|
+
context.data['foo'] = 'bar'
|
11
11
|
expect(context.data).to eq({})
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe Steno::Context::ThreadLocal do
|
16
|
-
include_context
|
16
|
+
include_context 'steno context'
|
17
17
|
|
18
|
-
let
|
18
|
+
let(:context) { Steno::Context::ThreadLocal.new }
|
19
19
|
|
20
|
-
it
|
20
|
+
it 'stores data local to threads' do
|
21
21
|
b1 = Barrier.new
|
22
22
|
b2 = Barrier.new
|
23
23
|
|
24
24
|
t1 = Thread.new do
|
25
|
-
context.data[
|
25
|
+
context.data['thread'] = 't1'
|
26
26
|
b1.release
|
27
27
|
b2.wait
|
28
|
-
expect(context.data[
|
28
|
+
expect(context.data['thread']).to eq('t1')
|
29
29
|
end
|
30
30
|
|
31
31
|
t2 = Thread.new do
|
32
32
|
b1.wait
|
33
|
-
expect(context.data[
|
34
|
-
context.data[
|
33
|
+
expect(context.data['thread']).to be_nil
|
34
|
+
context.data['thread'] = 't2'
|
35
35
|
b2.release
|
36
36
|
end
|
37
37
|
|
@@ -41,20 +41,20 @@ describe Steno::Context::ThreadLocal do
|
|
41
41
|
end
|
42
42
|
|
43
43
|
describe Steno::Context::FiberLocal do
|
44
|
-
include_context
|
44
|
+
include_context 'steno context'
|
45
45
|
|
46
46
|
let(:context) { Steno::Context::FiberLocal.new }
|
47
47
|
|
48
|
-
it
|
48
|
+
it 'stores data local to fibers' do
|
49
49
|
f2 = Fiber.new do
|
50
|
-
expect(context.data[
|
51
|
-
context.data[
|
50
|
+
expect(context.data['fiber']).to be_nil
|
51
|
+
context.data['fiber'] = 'f2'
|
52
52
|
end
|
53
53
|
|
54
54
|
f1 = Fiber.new do
|
55
|
-
context.data[
|
55
|
+
context.data['fiber'] = 'f1'
|
56
56
|
f2.resume
|
57
|
-
expect(context.data[
|
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
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'steno/core_ext'
|
4
4
|
|
5
5
|
module Foo
|
6
6
|
class Bar
|
@@ -8,31 +8,31 @@ module Foo
|
|
8
8
|
end
|
9
9
|
|
10
10
|
describe Module do
|
11
|
-
describe
|
12
|
-
it
|
11
|
+
describe '#logger' do
|
12
|
+
it 'requests a logger named after itself' do
|
13
13
|
x = Foo.logger
|
14
14
|
expect(x).to be_a(Steno::Logger)
|
15
|
-
expect(x.name).to include(
|
15
|
+
expect(x.name).to include('Foo')
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe Class do
|
21
|
-
describe
|
22
|
-
it
|
21
|
+
describe '#logger' do
|
22
|
+
it 'requests a logger named after itself' do
|
23
23
|
x = Foo::Bar.logger
|
24
24
|
expect(x).to be_a(Steno::Logger)
|
25
|
-
expect(x.name).to include(
|
25
|
+
expect(x.name).to include('Foo::Bar')
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe Object do
|
31
|
-
describe
|
32
|
-
it
|
31
|
+
describe '#logger' do
|
32
|
+
it 'requests a logger named after its class' do
|
33
33
|
x = Foo::Bar.new.logger
|
34
34
|
expect(x).to be_a(Steno::Logger)
|
35
|
-
expect(x.name).to include(
|
35
|
+
expect(x.name).to include('Foo::Bar')
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Codec::Json do
|
4
4
|
let(:codec) { Steno::Codec::Json.new }
|
5
|
-
let(:record) { make_record(:
|
5
|
+
let(:record) { make_record(data: { 'user' => 'data' }) }
|
6
6
|
|
7
|
-
describe
|
8
|
-
it
|
7
|
+
describe '#encode_record' do
|
8
|
+
it 'encodes records as json hashes' do
|
9
9
|
parsed = Yajl::Parser.parse(codec.encode_record(record))
|
10
10
|
expect(parsed.class).to eq(Hash)
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'encodes the timestamp as a float' do
|
14
14
|
parsed = Yajl::Parser.parse(codec.encode_record(record))
|
15
|
-
expect(parsed[
|
15
|
+
expect(parsed['timestamp'].class).to eq(Float)
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
19
|
-
rec = make_record(:
|
18
|
+
it 'escapes newlines' do
|
19
|
+
rec = make_record(message: "newline\ntest")
|
20
20
|
expect(codec.encode_record(rec)).to match(/newline\\ntest/)
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
rec = make_record(:
|
23
|
+
it 'escapes carriage returns' do
|
24
|
+
rec = make_record(message: "newline\rtest")
|
25
25
|
expect(codec.encode_record(rec)).to match(/newline\\rtest/)
|
26
26
|
end
|
27
27
|
|
28
|
-
it
|
28
|
+
it 'allows messages with valid encodings to pass through untouched' do
|
29
29
|
msg = "HI\u2600"
|
30
|
-
rec = make_record(:
|
30
|
+
rec = make_record(message: msg)
|
31
31
|
expect(codec.encode_record(rec)).to match(/#{msg}/)
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
35
|
-
msg = "HI\u2026".force_encoding(
|
36
|
-
rec = make_record(:
|
34
|
+
it 'treats messages with invalid encodings as binary data' do
|
35
|
+
msg = "HI\u2026".force_encoding('US-ASCII')
|
36
|
+
rec = make_record(message: msg)
|
37
37
|
expect(codec.encode_record(rec)).to match(/HI\\\\xe2\\\\x80\\\\xa6/)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
40
|
+
it 'does not use readable dates by default' do
|
41
41
|
expect(codec.iso8601_timestamps?).to eq(false)
|
42
42
|
end
|
43
43
|
|
44
|
-
context
|
45
|
-
let(:codec) { Steno::Codec::Json.new(
|
44
|
+
context 'when iso8601_timestamps is set' do
|
45
|
+
let(:codec) { Steno::Codec::Json.new(iso8601_timestamps: true) }
|
46
46
|
|
47
|
-
it
|
48
|
-
allow(record).to receive(:timestamp).and_return
|
47
|
+
it 'encodes timestamps as UTC-formatted strings' do
|
48
|
+
allow(record).to receive(:timestamp).and_return 1_396_473_763.811278 # 2014-04-02 22:22:43 +01:00
|
49
49
|
parsed = Yajl::Parser.parse(codec.encode_record(record))
|
50
50
|
|
51
|
-
expect(parsed[
|
52
|
-
expect(parsed[
|
51
|
+
expect(parsed['timestamp'].class).to eq(String)
|
52
|
+
expect(parsed['timestamp']).to eq('2014-04-02T21:22:43.811278Z')
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
55
|
+
it 'surfaces the property in a getter' do
|
56
56
|
expect(codec.iso8601_timestamps?).to eq(true)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
def make_record(opts = {})
|
62
|
-
Steno::Record.new(opts[:source] ||
|
62
|
+
Steno::Record.new(opts[:source] || 'my_source',
|
63
63
|
opts[:level] || :debug,
|
64
|
-
opts[:message] ||
|
64
|
+
opts[:message] || 'test message',
|
65
65
|
nil,
|
66
|
-
opts[:data]
|
66
|
+
opts[:data] || {})
|
67
67
|
end
|
68
68
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
require
|
3
|
+
require 'steno/json_prettifier'
|
4
4
|
|
5
5
|
describe Steno::JsonPrettifier do
|
6
6
|
let(:prettifier) { Steno::JsonPrettifier.new }
|
7
7
|
let(:codec) { Steno::Codec::Json.new }
|
8
8
|
|
9
|
-
describe
|
10
|
-
it
|
11
|
-
record = Steno::Record.new(
|
12
|
-
[
|
9
|
+
describe '#prettify_line' do
|
10
|
+
it 'returns a properly formatted string' do
|
11
|
+
record = Steno::Record.new('test', :info, 'message',
|
12
|
+
%w[filename line method], 'test' => 'data')
|
13
13
|
encoded = codec.encode_record(record)
|
14
14
|
prettified = prettifier.prettify_line(encoded)
|
15
15
|
|
@@ -23,16 +23,16 @@ describe Steno::JsonPrettifier do
|
|
23
23
|
'test=data', # User supplied data
|
24
24
|
'INFO', # Level
|
25
25
|
'--',
|
26
|
-
'message'
|
26
|
+
'message' # Log message
|
27
27
|
].join("\s+") + "\n"
|
28
28
|
expect(prettified).to match(exp_regex)
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'alwayses use the largest src len to determine src column width' do
|
32
32
|
test_srcs = [
|
33
33
|
'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 3),
|
34
34
|
'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 1),
|
35
|
-
'a' *
|
35
|
+
'a' * Steno::JsonPrettifier::MIN_COL_WIDTH,
|
36
36
|
'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 1),
|
37
37
|
'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH - 3),
|
38
38
|
'a' * (Steno::JsonPrettifier::MIN_COL_WIDTH + 3),
|
@@ -51,9 +51,9 @@ describe Steno::JsonPrettifier do
|
|
51
51
|
test_srcs.each do |src|
|
52
52
|
record = Steno::Record.new(src,
|
53
53
|
:info,
|
54
|
-
|
55
|
-
[
|
56
|
-
|
54
|
+
'message',
|
55
|
+
%w[filename line method],
|
56
|
+
'test' => 'data')
|
57
57
|
|
58
58
|
encoded = codec.encode_record(record)
|
59
59
|
prettified = prettifier.prettify_line(encoded)
|
@@ -64,21 +64,21 @@ describe Steno::JsonPrettifier do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
68
|
-
expect
|
69
|
-
prettifier.prettify_line(
|
70
|
-
|
67
|
+
it 'raises a parse error when the json-encoded string is not a hash' do
|
68
|
+
expect do
|
69
|
+
prettifier.prettify_line('[1,2,3]')
|
70
|
+
end.to raise_error(Steno::JsonPrettifier::ParseError)
|
71
71
|
end
|
72
72
|
|
73
|
-
it
|
74
|
-
expect
|
75
|
-
prettifier.prettify_line(
|
76
|
-
|
73
|
+
it 'raises a parse error when the json-encoded string is malformed' do
|
74
|
+
expect do
|
75
|
+
prettifier.prettify_line('blah')
|
76
|
+
end.to raise_error(Steno::JsonPrettifier::ParseError)
|
77
77
|
end
|
78
78
|
|
79
|
-
it
|
79
|
+
it 'works with a nil data field' do
|
80
80
|
line = prettifier.prettify_line('{"data":null}')
|
81
|
-
expect(line).to include(
|
81
|
+
expect(line).to include(' - ')
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
data/spec/unit/log_level_spec.rb
CHANGED
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::LogLevel do
|
4
4
|
let(:info_level) { Steno::LogLevel.new(:info, 2) }
|
5
5
|
let(:debug_level) { Steno::LogLevel.new(:debug, 1) }
|
6
6
|
|
7
|
-
it
|
7
|
+
it 'is comparable' do
|
8
8
|
expect(info_level > debug_level).to be_truthy
|
9
9
|
expect(debug_level > info_level).to be_falsey
|
10
10
|
expect(info_level == info_level).to be_truthy
|
11
11
|
end
|
12
12
|
|
13
|
-
describe
|
14
|
-
it
|
15
|
-
expect(info_level.to_s).to eq(
|
13
|
+
describe '#to_s' do
|
14
|
+
it 'returns the name of the level' do
|
15
|
+
expect(info_level.to_s).to eq('info')
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|