steno 1.2.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.
Files changed (43) hide show
  1. checksums.yaml +5 -13
  2. data/NOTICE +14 -0
  3. data/Rakefile +6 -8
  4. data/bin/steno-prettify +24 -25
  5. data/lib/steno/codec/base.rb +1 -1
  6. data/lib/steno/codec/json.rb +24 -14
  7. data/lib/steno/codec.rb +2 -2
  8. data/lib/steno/config.rb +23 -30
  9. data/lib/steno/context.rb +3 -3
  10. data/lib/steno/json_prettifier.rb +31 -30
  11. data/lib/steno/log_level.rb +1 -2
  12. data/lib/steno/logger.rb +22 -26
  13. data/lib/steno/record.rb +5 -15
  14. data/lib/steno/sink/base.rb +2 -3
  15. data/lib/steno/sink/counter.rb +4 -8
  16. data/lib/steno/sink/eventlog.rb +16 -17
  17. data/lib/steno/sink/fluentd.rb +4 -5
  18. data/lib/steno/sink/io.rb +8 -12
  19. data/lib/steno/sink/syslog.rb +19 -15
  20. data/lib/steno/sink.rb +6 -6
  21. data/lib/steno/tagged_logger.rb +2 -3
  22. data/lib/steno/version.rb +1 -1
  23. data/lib/steno.rb +16 -21
  24. data/spec/spec_helper.rb +4 -4
  25. data/spec/support/barrier.rb +2 -2
  26. data/spec/support/shared_context_specs.rb +4 -4
  27. data/spec/unit/config_spec.rb +134 -133
  28. data/spec/unit/context_spec.rb +19 -19
  29. data/spec/unit/core_ext_spec.rb +14 -14
  30. data/spec/unit/json_codec_spec.rb +43 -23
  31. data/spec/unit/json_prettifier_spec.rb +25 -25
  32. data/spec/unit/log_level_spec.rb +8 -9
  33. data/spec/unit/logger_spec.rb +53 -53
  34. data/spec/unit/record_spec.rb +15 -15
  35. data/spec/unit/sink/counter_spec.rb +7 -7
  36. data/spec/unit/sink/eventlog_spec.rb +14 -15
  37. data/spec/unit/sink/fluentd_spec.rb +28 -28
  38. data/spec/unit/sink/io_spec.rb +62 -62
  39. data/spec/unit/sink/syslog_spec.rb +54 -30
  40. data/spec/unit/steno_spec.rb +33 -33
  41. data/spec/unit/tagged_logger_spec.rb +20 -18
  42. data/steno.gemspec +28 -28
  43. metadata +62 -53
@@ -1,15 +1,15 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- require "steno/json_prettifier"
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 "#prettify_line" do
10
- it "should return a properly formatted string" do
11
- record = Steno::Record.new("test", :info, "message",
12
- ["filename", "line", "method"], "test" => "data")
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', # Log message
26
+ 'message' # Log message
27
27
  ].join("\s+") + "\n"
28
- prettified.should match(exp_regex)
28
+ expect(prettified).to match(exp_regex)
29
29
  end
30
30
 
31
- it "should always use the largest src len to determine src column width" do
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' * (Steno::JsonPrettifier::MIN_COL_WIDTH),
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
- "message",
55
- ["filename", "line", "method"],
56
- "test" => "data")
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.should == max_src_len
63
+ expect(src_col.length).to eq(max_src_len)
64
64
  end
65
65
  end
66
66
 
67
- it "should raise a parse error when the json-encoded string is not a hash" do
68
- expect {
69
- prettifier.prettify_line("[1,2,3]")
70
- }.to raise_error(Steno::JsonPrettifier::ParseError)
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 "should raise a parse error when the json-encoded string is malformed" do
74
- expect {
75
- prettifier.prettify_line("blah")
76
- }.to raise_error(Steno::JsonPrettifier::ParseError)
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 "should work with a nil data field" do
80
- line = prettifier.prettify_line(%@{"data":null}@)
81
- line.should include(" - ")
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
@@ -1,19 +1,18 @@
1
- require "spec_helper"
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 "should be comparable" do
8
- (info_level > debug_level).should be_true
9
- (debug_level > info_level).should be_false
10
- (info_level == info_level).should be_true
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 "#to_s" do
14
- it "should return the name of the level" do
15
- info_level.to_s.should == "info"
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
@@ -1,101 +1,101 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::Logger do
4
- let(:logger) { Steno::Logger.new("test", []) }
4
+ let(:logger) { Steno::Logger.new('test', []) }
5
5
 
6
- it "should provide #level, #levelf, and #level? methods for each log level" do
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 + "f", name.to_s + "?"].each do |meth|
9
- logger.respond_to?(meth).should be_true
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 "#level_active?" do
15
- it "should return a boolean indicating if the level is enabled" do
16
- logger.level_active?(:error).should be_true
17
- logger.level_active?(:info).should be_true
18
- logger.level_active?(:debug).should be_false
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 "#<level>?" do
23
- it "should return a boolean indiciating if <level> is enabled" do
24
- logger.error?.should be_true
25
- logger.info?.should be_true
26
- logger.debug?.should be_false
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 "#level" do
31
- it "should return the name of the currently active level" do
32
- logger.level.should == :info
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 "#level=" do
37
- it "should allow the level to be changed" do
36
+ describe '#level=' do
37
+ it 'allows the level to be changed' do
38
38
  logger.level = :warn
39
- logger.level.should == :warn
40
- logger.level_active?(:info).should be_false
41
- logger.level_active?(:warn).should be_true
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 "#log" do
46
- it "should not forward any messages for levels that are inactive" do
47
- sink = double("sink")
48
- sink.should_not_receive(:add_record)
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("test", [sink])
50
+ my_logger = Steno::Logger.new('test', [sink])
51
51
 
52
- my_logger.debug("test")
52
+ my_logger.debug('test')
53
53
  end
54
54
 
55
- it "should forward messages for levels that are active" do
56
- sink = double("sink")
57
- sink.should_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("test", [sink])
59
+ my_logger = Steno::Logger.new('test', [sink])
60
60
 
61
- my_logger.warn("test")
61
+ my_logger.warn('test')
62
62
  end
63
63
 
64
- it "should not invoke a supplied block if the level is inactive" do
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.should be_false
67
+ expect(invoked).to be_falsey
68
68
  end
69
69
 
70
- it "should invoke a supplied block if the level is active" do
70
+ it 'invokes a supplied block if the level is active' do
71
71
  invoked = false
72
72
  logger.warn { invoked = true }
73
- invoked.should be_true
73
+ expect(invoked).to be_truthy
74
74
  end
75
75
 
76
- it "creates a record with the proper level" do
77
- sink = double("sink")
78
- Steno::Record.should_receive(:new).with("test", :warn, "message", anything, anything).and_call_original
79
- sink.stub(:add_record)
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("test", [sink])
81
+ my_logger = Steno::Logger.new('test', [sink])
82
82
 
83
- my_logger.warn("message")
83
+ my_logger.warn('message')
84
84
  end
85
85
  end
86
86
 
87
- describe "#logf" do
88
- it "should format messages according to the supplied format string" do
89
- logger.should_receive(:log).with(:debug, "test 1 2.20")
90
- logger.debugf("test %d %0.2f", 1, 2.2)
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 "#tag" do
95
- it "should return a tagged logger" do
96
- tagged_logger = logger.tag("foo" => "bar")
97
- tagged_logger.should_not be_nil
98
- tagged_logger.user_data.should == { "foo" => "bar" }
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
@@ -1,30 +1,30 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Steno::Record do
4
- let(:message) { Array("test message") }
5
- let(:record) { Steno::Record.new("test", :info, message) }
4
+ let(:message) { Array('test message') }
5
+ let(:record) { Steno::Record.new('test', :info, message) }
6
6
 
7
- it "should set the process id" do
8
- record.process_id.should == Process.pid
7
+ it 'sets the process id' do
8
+ expect(record.process_id).to eq(Process.pid)
9
9
  end
10
10
 
11
- it "should set the thread id" do
12
- record.thread_id.should == Thread.current.object_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 "should set the fiber id(if available)", :needs_fibers => true do
16
- record.fiber_id.should == Fiber.current.object_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 "should set the source" do
20
- record.source.should == "test"
19
+ it 'sets the source' do
20
+ expect(record.source).to eq('test')
21
21
  end
22
22
 
23
- it "should stringify the message" do
24
- record.message.should be_a(String)
23
+ it 'stringifies the message' do
24
+ expect(record.message).to be_a(String)
25
25
  end
26
26
 
27
- it "should use a UTC timestamp" do
28
- record.timestamp.to_f.should be_within(0.1).of(Time.now.utc.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 "spec_helper"
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("source", level.name, "message")
9
+ Steno::Record.new('source', level.name, 'message')
10
10
  end
11
11
 
12
- describe "add_record" do
13
- it "counts added records" do
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 "to_json" do
22
- it "produces a valid json representation" do
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 "spec_helper"
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("source", level.name, "message")
9
+ Steno::Record.new('source', level.name, 'message')
10
10
  end
11
11
 
12
- describe "#add_record" do
13
-
14
- it "should append an encoded record with the correct priority" do
15
- eventlog = double("Win32::EventLog")
16
- Win32::EventLog.should_receive(:open) \
17
- .with('Application') \
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("codec")
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(:source => "CloudFoundry",
28
- :event_type => Win32::EventLog::INFO_TYPE,
29
- :data => record.message)
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 "#flush" do
36
- it "should do nothing" do
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 "spec_helper"
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("source", level.name, "message")
9
+ Steno::Record.new('source', level.name, 'message')
10
10
  end
11
11
 
12
- describe "#initialize" do
13
- it "should initialize FluentLogger with the default option" do
14
- Fluent::Logger::FluentLogger.should_receive(:new).with("steno", {
15
- :host => "127.0.0.1",
16
- :port => 24224,
17
- :buffer_limit => Fluent::Logger::FluentLogger::BUFFER_LIMIT,
18
- }).and_return()
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 "should initialize FliuentLogger with override options" do
23
- Fluent::Logger::FluentLogger.should_receive(:new).with("vcap", {
24
- :host => "localhost",
25
- :port => 8080,
26
- :buffer_limit => 1024,
27
- }).and_return()
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
- :tag_prefix => "vcap",
30
- :host => "localhost",
31
- :port => 8080,
32
- :buffer_limit => 1024
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 "#add_record" do
38
- it "should post an record with the correct tag" do
39
- fluentd = double("fluentd")
40
- Fluent::Logger::FluentLogger.should_receive(:new).and_return(fluentd)
41
- fluentd.should_receive(:post).with("source", record)
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