steno 1.2.4 → 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/NOTICE +14 -0
- data/Rakefile +6 -8
- data/bin/steno-prettify +24 -25
- data/lib/steno/codec/base.rb +1 -1
- data/lib/steno/codec/json.rb +24 -14
- data/lib/steno/codec.rb +2 -2
- data/lib/steno/config.rb +23 -30
- data/lib/steno/context.rb +3 -3
- data/lib/steno/json_prettifier.rb +31 -30
- 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 +19 -15
- 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 +134 -133
- data/spec/unit/context_spec.rb +19 -19
- data/spec/unit/core_ext_spec.rb +14 -14
- data/spec/unit/json_codec_spec.rb +43 -23
- data/spec/unit/json_prettifier_spec.rb +25 -25
- data/spec/unit/log_level_spec.rb +8 -9
- data/spec/unit/logger_spec.rb +53 -53
- data/spec/unit/record_spec.rb +15 -15
- 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 +28 -28
- data/spec/unit/sink/io_spec.rb +62 -62
- data/spec/unit/sink/syslog_spec.rb +54 -30
- data/spec/unit/steno_spec.rb +33 -33
- data/spec/unit/tagged_logger_spec.rb +20 -18
- data/steno.gemspec +28 -28
- metadata +62 -53
@@ -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
|
-
prettified.
|
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,34 +51,34 @@ 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)
|
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
|
|
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
|
80
|
-
line = prettifier.prettify_line(
|
81
|
-
line.
|
79
|
+
it 'works with a nil data field' do
|
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
@@ -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
|
8
|
-
(info_level > debug_level).
|
9
|
-
(debug_level > info_level).
|
10
|
-
(info_level == info_level).
|
7
|
+
it 'is comparable' do
|
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
|
-
describe
|
14
|
-
it
|
15
|
-
info_level.to_s.
|
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
|
data/spec/unit/logger_spec.rb
CHANGED
@@ -1,101 +1,101 @@
|
|
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 +
|
9
|
-
logger.respond_to?(meth).
|
8
|
+
[name, name.to_s + 'f', name.to_s + '?'].each do |meth|
|
9
|
+
expect(logger.respond_to?(meth)).to be_truthy
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe
|
15
|
-
it
|
16
|
-
logger.level_active?(:error).
|
17
|
-
logger.level_active?(:info).
|
18
|
-
logger.level_active?(:debug).
|
14
|
+
describe '#level_active?' do
|
15
|
+
it 'returns a boolean indicating if the level is enabled' do
|
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
|
-
describe
|
23
|
-
it
|
24
|
-
logger.error
|
25
|
-
logger.info
|
26
|
-
logger.debug
|
22
|
+
describe '#<level>?' do
|
23
|
+
it 'returns a boolean indiciating if <level> is enabled' do
|
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
|
-
describe
|
31
|
-
it
|
32
|
-
logger.level.
|
30
|
+
describe '#level' do
|
31
|
+
it 'returns the name of the currently active level' do
|
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
|
-
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
|
-
describe
|
46
|
-
it
|
47
|
-
sink = double(
|
48
|
-
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
|
-
sink.
|
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
|
-
invoked.
|
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
|
-
invoked.
|
73
|
+
expect(invoked).to be_truthy
|
74
74
|
end
|
75
75
|
|
76
|
-
it
|
77
|
-
sink = double(
|
78
|
-
Steno::Record.
|
79
|
-
sink.
|
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
|
+
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
|
-
logger.
|
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
|
-
tagged_logger.
|
98
|
-
tagged_logger.user_data.
|
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
|
8
|
-
record.process_id.
|
7
|
+
it 'sets the process id' do
|
8
|
+
expect(record.process_id).to eq(Process.pid)
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
12
|
-
record.thread_id.
|
11
|
+
it 'sets the thread id' do
|
12
|
+
expect(record.thread_id).to eq(Thread.current.object_id)
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
16
|
-
record.fiber_id.
|
15
|
+
it 'sets the fiber id(if available)', :needs_fibers do
|
16
|
+
expect(record.fiber_id).to eq(Fiber.current.object_id)
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
20
|
-
record.source.
|
19
|
+
it 'sets the source' do
|
20
|
+
expect(record.source).to eq('test')
|
21
21
|
end
|
22
22
|
|
23
|
-
it
|
24
|
-
record.message.
|
23
|
+
it 'stringifies the message' do
|
24
|
+
expect(record.message).to be_a(String)
|
25
25
|
end
|
26
26
|
|
27
|
-
it
|
28
|
-
record.timestamp.to_f.
|
27
|
+
it 'uses a UTC timestamp' do
|
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,41 +6,41 @@ 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
|
-
Fluent::Logger::FluentLogger.
|
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
|
-
Fluent::Logger::FluentLogger.
|
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(
|
40
|
-
Fluent::Logger::FluentLogger.
|
41
|
-
fluentd.
|
42
|
-
sink = Steno::Sink::Fluentd.new
|
37
|
+
describe '#add_record' do
|
38
|
+
it 'posts an record with the correct tag' do
|
39
|
+
fluentd = double('fluentd')
|
40
|
+
expect(Fluent::Logger::FluentLogger).to receive(:new).and_return(fluentd)
|
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
|
46
|
-
end
|
46
|
+
end
|