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/logger_spec.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Logger do
|
4
|
-
let(:logger) { Steno::Logger.new(
|
4
|
+
let(:logger) { Steno::Logger.new('test', []) }
|
5
5
|
|
6
|
-
it
|
6
|
+
it 'provides #level, #levelf, and #level? methods for each log level' do
|
7
7
|
Steno::Logger::LEVELS.each do |name, _|
|
8
|
-
[name, name.to_s +
|
8
|
+
[name, name.to_s + 'f', name.to_s + '?'].each do |meth|
|
9
9
|
expect(logger.respond_to?(meth)).to be_truthy
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
14
|
+
describe '#level_active?' do
|
15
|
+
it 'returns a boolean indicating if the level is enabled' do
|
16
16
|
expect(logger.level_active?(:error)).to be_truthy
|
17
17
|
expect(logger.level_active?(:info)).to be_truthy
|
18
18
|
expect(logger.level_active?(:debug)).to be_falsey
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe
|
23
|
-
it
|
22
|
+
describe '#<level>?' do
|
23
|
+
it 'returns a boolean indiciating if <level> is enabled' do
|
24
24
|
expect(logger.error?).to be_truthy
|
25
25
|
expect(logger.info?).to be_truthy
|
26
26
|
expect(logger.debug?).to be_falsey
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
describe
|
31
|
-
it
|
30
|
+
describe '#level' do
|
31
|
+
it 'returns the name of the currently active level' do
|
32
32
|
expect(logger.level).to eq(:info)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
37
|
-
it
|
36
|
+
describe '#level=' do
|
37
|
+
it 'allows the level to be changed' do
|
38
38
|
logger.level = :warn
|
39
39
|
expect(logger.level).to eq(:warn)
|
40
40
|
expect(logger.level_active?(:info)).to be_falsey
|
@@ -42,60 +42,60 @@ describe Steno::Logger do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
describe
|
46
|
-
it
|
47
|
-
sink = double(
|
48
|
-
expect(sink).
|
45
|
+
describe '#log' do
|
46
|
+
it 'does not forward any messages for levels that are inactive' do
|
47
|
+
sink = double('sink')
|
48
|
+
expect(sink).not_to receive(:add_record)
|
49
49
|
|
50
|
-
my_logger = Steno::Logger.new(
|
50
|
+
my_logger = Steno::Logger.new('test', [sink])
|
51
51
|
|
52
|
-
my_logger.debug(
|
52
|
+
my_logger.debug('test')
|
53
53
|
end
|
54
54
|
|
55
|
-
it
|
56
|
-
sink = double(
|
57
|
-
expect(sink).to receive(:add_record).with(any_args
|
55
|
+
it 'forwards messages for levels that are active' do
|
56
|
+
sink = double('sink')
|
57
|
+
expect(sink).to receive(:add_record).with(any_args)
|
58
58
|
|
59
|
-
my_logger = Steno::Logger.new(
|
59
|
+
my_logger = Steno::Logger.new('test', [sink])
|
60
60
|
|
61
|
-
my_logger.warn(
|
61
|
+
my_logger.warn('test')
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it 'does not invoke a supplied block if the level is inactive' do
|
65
65
|
invoked = false
|
66
66
|
logger.debug { invoked = true }
|
67
67
|
expect(invoked).to be_falsey
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
70
|
+
it 'invokes a supplied block if the level is active' do
|
71
71
|
invoked = false
|
72
72
|
logger.warn { invoked = true }
|
73
73
|
expect(invoked).to be_truthy
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
sink = double(
|
78
|
-
expect(Steno::Record).to receive(:new).with(
|
76
|
+
it 'creates a record with the proper level' do
|
77
|
+
sink = double('sink')
|
78
|
+
expect(Steno::Record).to receive(:new).with('test', :warn, 'message', anything, anything).and_call_original
|
79
79
|
allow(sink).to receive(:add_record)
|
80
80
|
|
81
|
-
my_logger = Steno::Logger.new(
|
81
|
+
my_logger = Steno::Logger.new('test', [sink])
|
82
82
|
|
83
|
-
my_logger.warn(
|
83
|
+
my_logger.warn('message')
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
describe
|
88
|
-
it
|
89
|
-
expect(logger).to receive(:log).with(:debug,
|
90
|
-
logger.debugf(
|
87
|
+
describe '#logf' do
|
88
|
+
it 'formats messages according to the supplied format string' do
|
89
|
+
expect(logger).to receive(:log).with(:debug, 'test 1 2.20')
|
90
|
+
logger.debugf('test %d %0.2f', 1, 2.2)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
describe
|
95
|
-
it
|
96
|
-
tagged_logger = logger.tag(
|
97
|
-
expect(tagged_logger).
|
98
|
-
expect(tagged_logger.user_data).to eq({
|
94
|
+
describe '#tag' do
|
95
|
+
it 'returns a tagged logger' do
|
96
|
+
tagged_logger = logger.tag('foo' => 'bar')
|
97
|
+
expect(tagged_logger).not_to 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
@@ -1,30 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Record do
|
4
|
-
let(:message) { Array(
|
5
|
-
let(:record) { Steno::Record.new(
|
4
|
+
let(:message) { Array('test message') }
|
5
|
+
let(:record) { Steno::Record.new('test', :info, message) }
|
6
6
|
|
7
|
-
it
|
7
|
+
it 'sets the process id' do
|
8
8
|
expect(record.process_id).to eq(Process.pid)
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it 'sets the thread id' do
|
12
12
|
expect(record.thread_id).to eq(Thread.current.object_id)
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it 'sets the fiber id(if available)', :needs_fibers do
|
16
16
|
expect(record.fiber_id).to eq(Fiber.current.object_id)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
expect(record.source).to eq(
|
19
|
+
it 'sets the source' do
|
20
|
+
expect(record.source).to eq('test')
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
23
|
+
it 'stringifies the message' do
|
24
24
|
expect(record.message).to be_a(String)
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
27
|
+
it 'uses a UTC timestamp' do
|
28
28
|
expect(record.timestamp.to_f).to be_within(0.1).of(Time.now.utc.to_f)
|
29
29
|
end
|
30
30
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Sink::Counter do
|
4
4
|
let(:level) do
|
@@ -6,11 +6,11 @@ describe Steno::Sink::Counter do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:record) do
|
9
|
-
Steno::Record.new(
|
9
|
+
Steno::Record.new('source', level.name, 'message')
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
12
|
+
describe 'add_record' do
|
13
|
+
it 'counts added records' do
|
14
14
|
expect(subject.counts).to be_empty
|
15
15
|
subject.add_record(record)
|
16
16
|
expect(subject.counts.size).to eq 1
|
@@ -18,10 +18,10 @@ describe Steno::Sink::Counter do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
21
|
+
describe 'to_json' do
|
22
|
+
it 'produces a valid json representation' do
|
23
23
|
subject.add_record(record)
|
24
24
|
expect(subject.to_json).to match '"info":1'
|
25
25
|
end
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
if Steno::Sink::WINDOWS
|
3
3
|
describe Steno::Sink::Eventlog do
|
4
4
|
let(:level) do
|
@@ -6,34 +6,33 @@ if Steno::Sink::WINDOWS
|
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:record) do
|
9
|
-
Steno::Record.new(
|
9
|
+
Steno::Record.new('source', level.name, 'message')
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
.and_return(eventlog)
|
12
|
+
describe '#add_record' do
|
13
|
+
it 'appends an encoded record with the correct priority' do
|
14
|
+
eventlog = double('Win32::EventLog')
|
15
|
+
Win32::EventLog.should_receive(:open)
|
16
|
+
.with('Application')
|
17
|
+
.and_return(eventlog)
|
19
18
|
|
20
19
|
sink = Steno::Sink::Eventlog.instance
|
21
20
|
sink.open
|
22
21
|
|
23
|
-
codec = double(
|
22
|
+
codec = double('codec')
|
24
23
|
codec.should_receive(:encode_record).with(record).and_return(record.message)
|
25
24
|
sink.codec = codec
|
26
25
|
|
27
|
-
eventlog.should_receive(:report_event).with(:
|
28
|
-
:
|
29
|
-
:
|
26
|
+
eventlog.should_receive(:report_event).with(source: 'CloudFoundry',
|
27
|
+
event_type: Win32::EventLog::INFO_TYPE,
|
28
|
+
data: record.message)
|
30
29
|
|
31
30
|
sink.add_record(record)
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
describe
|
36
|
-
it
|
34
|
+
describe '#flush' do
|
35
|
+
it 'does nothing' do
|
37
36
|
Steno::Sink::Eventlog.instance.flush
|
38
37
|
end
|
39
38
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Sink::IO do
|
4
4
|
let(:level) do
|
@@ -6,40 +6,40 @@ describe Steno::Sink::IO do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:record) do
|
9
|
-
Steno::Record.new(
|
9
|
+
Steno::Record.new('source', level.name, 'message')
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
expect(Fluent::Logger::FluentLogger).to receive(:new).with(
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
sink = Steno::Sink::Fluentd.new
|
12
|
+
describe '#initialize' do
|
13
|
+
it 'initializes FluentLogger with the default option' do
|
14
|
+
expect(Fluent::Logger::FluentLogger).to receive(:new).with('steno', {
|
15
|
+
host: '127.0.0.1',
|
16
|
+
port: 24_224,
|
17
|
+
buffer_limit: Fluent::Logger::FluentLogger::BUFFER_LIMIT
|
18
|
+
}).and_return(nil)
|
19
|
+
sink = Steno::Sink::Fluentd.new
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
expect(Fluent::Logger::FluentLogger).to receive(:new).with(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
it 'initializes FliuentLogger with override options' do
|
23
|
+
expect(Fluent::Logger::FluentLogger).to receive(:new).with('vcap', {
|
24
|
+
host: 'localhost',
|
25
|
+
port: 8080,
|
26
|
+
buffer_limit: 1024
|
27
|
+
}).and_return(nil)
|
28
28
|
sink = Steno::Sink::Fluentd.new({
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
tag_prefix: 'vcap',
|
30
|
+
host: 'localhost',
|
31
|
+
port: 8080,
|
32
|
+
buffer_limit: 1024
|
33
|
+
})
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
38
|
-
it
|
39
|
-
fluentd = double(
|
37
|
+
describe '#add_record' do
|
38
|
+
it 'posts an record with the correct tag' do
|
39
|
+
fluentd = double('fluentd')
|
40
40
|
expect(Fluent::Logger::FluentLogger).to receive(:new).and_return(fluentd)
|
41
|
-
expect(fluentd).to receive(:post).with(
|
42
|
-
sink = Steno::Sink::Fluentd.new
|
41
|
+
expect(fluentd).to receive(:post).with('source', record)
|
42
|
+
sink = Steno::Sink::Fluentd.new
|
43
43
|
sink.add_record(record)
|
44
44
|
end
|
45
45
|
end
|
data/spec/unit/sink/io_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Steno::Sink::IO do
|
4
4
|
let(:level) do
|
@@ -6,103 +6,103 @@ describe Steno::Sink::IO do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:record) do
|
9
|
-
Steno::Record.new(
|
9
|
+
Steno::Record.new('source', level.name, 'message')
|
10
10
|
end
|
11
11
|
|
12
|
-
describe
|
13
|
-
it
|
14
|
-
mock_handle = double(
|
12
|
+
describe '.for_file' do
|
13
|
+
it 'returns a new sink configured to append to the file at path with autosync set to true by default' do
|
14
|
+
mock_handle = double('file handle')
|
15
15
|
|
16
|
-
expect(File).to receive(:open).with(
|
16
|
+
expect(File).to receive(:open).with('path', 'a+').and_return(mock_handle)
|
17
17
|
expect(mock_handle).to receive(:sync=).with(true)
|
18
18
|
|
19
|
-
mock_sink = double(
|
19
|
+
mock_sink = double('sink')
|
20
20
|
expect(Steno::Sink::IO).to receive(:new).with(mock_handle,
|
21
|
-
|
22
|
-
|
21
|
+
max_retries: 10)
|
22
|
+
.and_return(mock_sink)
|
23
23
|
|
24
|
-
returned = Steno::Sink::IO.for_file(
|
25
|
-
:
|
24
|
+
returned = Steno::Sink::IO.for_file('path',
|
25
|
+
max_retries: 10)
|
26
26
|
expect(returned).to eq(mock_sink)
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
mock_handle = double(
|
29
|
+
it 'returns a new sink configured to append to the file at path with specified options' do
|
30
|
+
mock_handle = double('file handle')
|
31
31
|
|
32
|
-
expect(File).to receive(:open).with(
|
32
|
+
expect(File).to receive(:open).with('path', 'a+').and_return(mock_handle)
|
33
33
|
expect(mock_handle).to receive(:sync=).with(false)
|
34
34
|
|
35
|
-
mock_sink = double(
|
35
|
+
mock_sink = double('sink')
|
36
36
|
expect(Steno::Sink::IO).to receive(:new).with(mock_handle,
|
37
|
-
|
38
|
-
|
37
|
+
max_retries: 10)
|
38
|
+
.and_return(mock_sink)
|
39
39
|
|
40
|
-
returned = Steno::Sink::IO.for_file(
|
41
|
-
:
|
42
|
-
:
|
40
|
+
returned = Steno::Sink::IO.for_file('path',
|
41
|
+
autoflush: false,
|
42
|
+
max_retries: 10)
|
43
43
|
expect(returned).to eq(mock_sink)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
describe
|
48
|
-
it
|
49
|
-
codec = double(
|
47
|
+
describe '#add_record' do
|
48
|
+
it 'encodes the record and write it to the underlying io object' do
|
49
|
+
codec = double('codec')
|
50
50
|
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
51
51
|
|
52
|
-
io = double(
|
52
|
+
io = double('io')
|
53
53
|
expect(io).to receive(:write).with(record.message)
|
54
54
|
|
55
|
-
Steno::Sink::IO.new(io, :
|
55
|
+
Steno::Sink::IO.new(io, codec: codec).add_record(record)
|
56
56
|
end
|
57
57
|
|
58
|
-
it
|
59
|
-
codec = double(
|
58
|
+
it 'bies default not retry on IOError' do
|
59
|
+
codec = double('codec')
|
60
60
|
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
61
61
|
|
62
|
-
io = double(
|
62
|
+
io = double('io')
|
63
63
|
|
64
64
|
expect(io).to receive(:write).with(record.message).ordered.and_raise(IOError)
|
65
65
|
|
66
66
|
expect do
|
67
|
-
Steno::Sink::IO.new(io, :
|
67
|
+
Steno::Sink::IO.new(io, codec: codec).add_record(record)
|
68
68
|
end.to raise_error(IOError)
|
69
69
|
end
|
70
70
|
|
71
|
-
it
|
72
|
-
codec = double(
|
71
|
+
it 'retries not more than specified number of times on IOError' do
|
72
|
+
codec = double('codec')
|
73
73
|
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
74
74
|
|
75
|
-
io = double(
|
75
|
+
io = double('io')
|
76
76
|
|
77
|
-
expect(io).to receive(:write).exactly(3).times.with(record.message)
|
78
|
-
|
77
|
+
expect(io).to receive(:write).exactly(3).times.with(record.message)
|
78
|
+
.and_raise(IOError)
|
79
79
|
|
80
80
|
expect do
|
81
|
-
Steno::Sink::IO.new(io, :
|
82
|
-
|
81
|
+
Steno::Sink::IO.new(io, codec: codec, max_retries: 2)
|
82
|
+
.add_record(record)
|
83
83
|
end.to raise_error(IOError)
|
84
84
|
end
|
85
85
|
|
86
|
-
it
|
87
|
-
codec = double(
|
86
|
+
it 'retries on IOError and succeed' do
|
87
|
+
codec = double('codec')
|
88
88
|
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
89
89
|
|
90
|
-
io = double(
|
91
|
-
expect(io).to receive(:write).with(record.message).once
|
92
|
-
|
93
|
-
expect(io).to receive(:write).with(record.message).once.ordered
|
94
|
-
|
90
|
+
io = double('io')
|
91
|
+
expect(io).to receive(:write).with(record.message).once
|
92
|
+
.and_raise(IOError)
|
93
|
+
expect(io).to receive(:write).with(record.message).once.ordered
|
94
|
+
.and_return(record.message)
|
95
95
|
|
96
96
|
expect do
|
97
|
-
Steno::Sink::IO.new(io, :
|
98
|
-
|
99
|
-
end.
|
97
|
+
Steno::Sink::IO.new(io, codec: codec, max_retries: 1)
|
98
|
+
.add_record(record)
|
99
|
+
end.not_to raise_error
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe
|
104
|
-
it
|
105
|
-
io = double(
|
103
|
+
describe '#flush' do
|
104
|
+
it 'calls flush on the underlying io object' do
|
105
|
+
io = double('io')
|
106
106
|
expect(io).to receive(:flush)
|
107
107
|
|
108
108
|
Steno::Sink::IO.new(io).flush
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
unless Steno::Sink::WINDOWS
|
3
3
|
describe Steno::Sink::Syslog do
|
4
4
|
let(:level) do
|
@@ -6,50 +6,50 @@ unless Steno::Sink::WINDOWS
|
|
6
6
|
end
|
7
7
|
|
8
8
|
let(:record) do
|
9
|
-
Steno::Record.new(
|
9
|
+
Steno::Record.new('source', level.name, 'message')
|
10
10
|
end
|
11
11
|
|
12
12
|
let(:record_with_big_message) do
|
13
|
-
Steno::Record.new(
|
14
|
-
|
13
|
+
Steno::Record.new('source', level.name,
|
14
|
+
'a' * (Steno::Sink::Syslog::MAX_MESSAGE_SIZE + 1))
|
15
15
|
end
|
16
16
|
|
17
|
-
describe
|
17
|
+
describe '#add_record' do
|
18
18
|
after do
|
19
19
|
Syslog::Logger.syslog = nil
|
20
20
|
end
|
21
21
|
|
22
|
-
it
|
23
|
-
identity =
|
22
|
+
it 'appends an encoded record with the correct priority' do
|
23
|
+
identity = 'test'
|
24
24
|
|
25
|
-
syslog = double(
|
25
|
+
syslog = double('syslog', facility: nil)
|
26
26
|
expect(Syslog).to receive(:open).and_return(syslog)
|
27
27
|
|
28
28
|
sink = Steno::Sink::Syslog.instance
|
29
29
|
sink.open(identity)
|
30
30
|
|
31
|
-
codec = double(
|
31
|
+
codec = double('codec')
|
32
32
|
expect(codec).to receive(:encode_record).with(record).and_return(record.message)
|
33
33
|
sink.codec = codec
|
34
34
|
|
35
|
-
expect(syslog).to receive(:log).with(Syslog::LOG_INFO,
|
35
|
+
expect(syslog).to receive(:log).with(Syslog::LOG_INFO, '%s', record.message)
|
36
36
|
|
37
37
|
sink.add_record(record)
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
identity =
|
40
|
+
it 'truncates the record message if its greater than than allowed size' do
|
41
|
+
identity = 'test'
|
42
42
|
|
43
|
-
syslog = double(
|
43
|
+
syslog = double('syslog', facility: nil)
|
44
44
|
expect(Syslog).to receive(:open).and_return(syslog)
|
45
45
|
|
46
46
|
sink = Steno::Sink::Syslog.instance
|
47
47
|
sink.open(identity)
|
48
48
|
|
49
|
-
truncated = record_with_big_message.message
|
50
|
-
|
49
|
+
truncated = record_with_big_message.message
|
50
|
+
.slice(0..Steno::Sink::Syslog::MAX_MESSAGE_SIZE - 4)
|
51
51
|
truncated << Steno::Sink::Syslog::TRUNCATE_POSTFIX
|
52
|
-
codec = double(
|
52
|
+
codec = double('codec')
|
53
53
|
expect(codec).to receive(:encode_record) do |*args|
|
54
54
|
expect(args.size).to eq(1)
|
55
55
|
expect(args[0].message).to eq(truncated)
|
@@ -60,14 +60,38 @@ unless Steno::Sink::WINDOWS
|
|
60
60
|
|
61
61
|
sink.codec = codec
|
62
62
|
|
63
|
-
expect(syslog).to receive(:log).with(Syslog::LOG_INFO,
|
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
|
67
|
+
|
68
|
+
context 'when level is off' do
|
69
|
+
let(:level) do
|
70
|
+
Steno::Logger.lookup_level(:off)
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'does not write out logs' do
|
74
|
+
identity = 'test'
|
75
|
+
|
76
|
+
syslog = double('syslog', facility: nil, log: nil)
|
77
|
+
expect(Syslog).to receive(:open).and_return(syslog)
|
78
|
+
|
79
|
+
sink = Steno::Sink::Syslog.instance
|
80
|
+
sink.open(identity)
|
81
|
+
|
82
|
+
codec = double('codec', encode_record: nil)
|
83
|
+
sink.codec = codec
|
84
|
+
|
85
|
+
sink.add_record(record)
|
86
|
+
|
87
|
+
expect(codec).not_to have_received(:encode_record)
|
88
|
+
expect(syslog).not_to have_received(:log)
|
89
|
+
end
|
90
|
+
end
|
67
91
|
end
|
68
92
|
|
69
|
-
describe
|
70
|
-
it
|
93
|
+
describe '#flush' do
|
94
|
+
it 'does nothing' do
|
71
95
|
Steno::Sink::Syslog.instance.flush
|
72
96
|
end
|
73
97
|
end
|