yell 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -1
  3. data/.travis.yml +1 -2
  4. data/Gemfile +5 -1
  5. data/README.md +67 -14
  6. data/examples/004.1-colorizing-the-log-output.rb +4 -4
  7. data/lib/yell.rb +19 -10
  8. data/lib/yell/adapters.rb +23 -26
  9. data/lib/yell/adapters/base.rb +8 -2
  10. data/lib/yell/adapters/datefile.rb +45 -42
  11. data/lib/yell/adapters/file.rb +10 -5
  12. data/lib/yell/adapters/io.rb +52 -48
  13. data/lib/yell/adapters/streams.rb +10 -2
  14. data/lib/yell/configuration.rb +1 -1
  15. data/lib/yell/event.rb +4 -4
  16. data/lib/yell/formatter.rb +11 -25
  17. data/lib/yell/helpers/adapters.rb +51 -0
  18. data/lib/yell/helpers/base.rb +19 -0
  19. data/lib/yell/helpers/formatter.rb +31 -0
  20. data/lib/yell/helpers/level.rb +36 -0
  21. data/lib/yell/helpers/silencer.rb +32 -0
  22. data/lib/yell/helpers/tracer.rb +48 -0
  23. data/lib/yell/level.rb +38 -47
  24. data/lib/yell/logger.rb +53 -73
  25. data/lib/yell/repository.rb +31 -29
  26. data/lib/yell/silencer.rb +69 -0
  27. data/lib/yell/version.rb +1 -1
  28. data/spec/spec_helper.rb +21 -9
  29. data/spec/yell/adapters/base_spec.rb +17 -34
  30. data/spec/yell/adapters/datefile_spec.rb +109 -66
  31. data/spec/yell/adapters/file_spec.rb +18 -18
  32. data/spec/yell/adapters/io_spec.rb +17 -13
  33. data/spec/yell/adapters/streams_spec.rb +7 -7
  34. data/spec/yell/adapters_spec.rb +18 -23
  35. data/spec/yell/configuration_spec.rb +7 -7
  36. data/spec/yell/event_spec.rb +25 -27
  37. data/spec/yell/formatter_spec.rb +89 -82
  38. data/spec/yell/level_spec.rb +119 -94
  39. data/spec/yell/loggable_spec.rb +6 -5
  40. data/spec/yell/logger_spec.rb +106 -66
  41. data/spec/yell/repository_spec.rb +23 -38
  42. data/spec/yell/silencer_spec.rb +49 -0
  43. data/spec/yell_spec.rb +24 -27
  44. metadata +16 -9
@@ -8,59 +8,63 @@ describe Yell::Adapters::Io do
8
8
  it "should set default :format" do
9
9
  adapter = Yell::Adapters::Io.new
10
10
 
11
- adapter.format.should be_kind_of(Yell::Formatter)
11
+ expect(adapter.format).to be_kind_of(Yell::Formatter)
12
12
  end
13
13
 
14
- context :level do
14
+ context ":level" do
15
15
  let(:level) { Yell::Level.new(:warn) }
16
16
 
17
17
  it "should set the level" do
18
18
  adapter = Yell::Adapters::Io.new(:level => level)
19
- adapter.level.should == level
19
+
20
+ expect(adapter.level).to eq(level)
20
21
  end
21
22
 
22
23
  it "should set the level when block was given" do
23
24
  adapter = Yell::Adapters::Io.new { |a| a.level = level }
24
- adapter.level.should == level
25
+
26
+ expect(adapter.level).to eq(level)
25
27
  end
26
28
  end
27
29
 
28
- context :format do
30
+ context ":format" do
29
31
  let(:format) { Yell::Formatter.new }
30
32
 
31
33
  it "should set the level" do
32
34
  adapter = Yell::Adapters::Io.new(:format => format)
33
- adapter.format.should == format
35
+
36
+ expect(adapter.format).to eq(format)
34
37
  end
35
38
 
36
39
  it "should set the level when block was given" do
37
40
  adapter = Yell::Adapters::Io.new { |a| a.format = format }
38
- adapter.format.should == format
41
+
42
+ expect(adapter.format).to eq(format)
39
43
  end
40
44
  end
41
45
  end
42
46
 
43
- context :write do
47
+ context "#write" do
44
48
  let(:logger) { Yell::Logger.new }
45
49
  let(:event) { Yell::Event.new(logger, 1, "Hello World") }
46
50
  let(:adapter) { Yell::Adapters::Io.new }
47
51
  let(:stream) { File.new('/dev/null', 'w') }
48
52
 
49
53
  before do
50
- stub( adapter ).stream { stream }
54
+ stub(adapter).stream { stream }
51
55
  end
52
56
 
53
57
  it "should format the message" do
54
- mock.proxy( adapter.format ).format( event )
58
+ mock.proxy(adapter.format).format( event )
55
59
 
56
- adapter.write( event )
60
+ adapter.write(event)
57
61
  end
58
62
 
59
63
  it "should print formatted message to stream" do
60
64
  formatted = Yell::Formatter.new.format( event )
61
- mock( stream ).syswrite( formatted << "\n" )
65
+ mock(stream).syswrite( formatted << "\n" )
62
66
 
63
- adapter.write( event )
67
+ adapter.write(event)
64
68
  end
65
69
  end
66
70
 
@@ -2,24 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe Yell::Adapters::Stdout do
4
4
 
5
- it { should be_kind_of Yell::Adapters::Io }
5
+ it { should be_kind_of(Yell::Adapters::Io) }
6
6
 
7
- context :stream do
7
+ context "#stream" do
8
8
  subject { Yell::Adapters::Stdout.new.send :stream }
9
9
 
10
- it { should be_kind_of IO }
10
+ it { should be_kind_of(IO) }
11
11
  end
12
12
 
13
13
  end
14
14
 
15
15
  describe Yell::Adapters::Stderr do
16
16
 
17
- it { should be_kind_of Yell::Adapters::Io }
17
+ it { should be_kind_of(Yell::Adapters::Io) }
18
18
 
19
- context :stream do
20
- subject { Yell::Adapters::Stderr.new.send :stream }
19
+ context "#stream" do
20
+ subject { Yell::Adapters::Stderr.new.send(:stream) }
21
21
 
22
- it { should be_kind_of IO }
22
+ it { should be_kind_of(IO) }
23
23
  end
24
24
 
25
25
  end
@@ -2,46 +2,41 @@ require 'spec_helper'
2
2
 
3
3
  describe Yell::Adapters do
4
4
 
5
- context :new do
6
- context "given a Yell::Adapters::Base ancestor" do
7
- let(:stdout) { Yell::Adapters::Stdout.new }
5
+ context ".new" do
6
+ it "should accept an adapter instance" do
7
+ stdout = Yell::Adapters::Stdout.new
8
+ adapter = Yell::Adapters.new(stdout)
8
9
 
9
- it "should return the instance" do
10
- Yell::Adapters.new( stdout ).should == stdout
11
- end
10
+ expect(adapter).to eq(stdout)
12
11
  end
13
12
 
14
- context "given STDOUT" do
15
- it "should initialize Stdout adapter" do
16
- mock.proxy( Yell::Adapters::Stdout ).new( anything )
13
+ it "should accept STDOUT" do
14
+ mock.proxy(Yell::Adapters::Stdout).new(anything)
17
15
 
18
- Yell::Adapters.new STDOUT
19
- end
16
+ Yell::Adapters.new(STDOUT)
20
17
  end
21
18
 
22
- context "given STDERR" do
23
- it "should initialize Stderr adapter" do
24
- mock.proxy( Yell::Adapters::Stderr ).new( anything )
19
+ it "should accept STDERR" do
20
+ mock.proxy(Yell::Adapters::Stderr).new(anything)
25
21
 
26
- Yell::Adapters.new STDERR
27
- end
22
+ Yell::Adapters.new(STDERR)
28
23
  end
29
24
 
30
- context "given an unregistered adapter" do
31
- it "should raise AdapterNotFound" do
32
- lambda { Yell::Adapters.new :unknown }.should raise_error Yell::AdapterNotFound
33
- end
25
+ it "should raise an unregistered adapter" do
26
+ expect {
27
+ Yell::Adapters.new :unknown
28
+ }.to raise_error(Yell::AdapterNotFound)
34
29
  end
35
30
  end
36
31
 
37
- context :register do
32
+ context ".register" do
38
33
  let(:name) { :test }
39
34
  let(:klass) { mock }
40
35
 
41
- before { Yell::Adapters.register( name, klass ) }
36
+ before { Yell::Adapters.register(name, klass) }
42
37
 
43
38
  it "should allow to being called from :new" do
44
- mock( klass ).new( anything )
39
+ mock(klass).new(anything)
45
40
 
46
41
  Yell::Adapters.new(name)
47
42
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Yell::Configuration do
4
4
 
5
- describe ":load!" do
5
+ describe ".load!" do
6
6
  let(:file) { fixture_path + '/yell.yml' }
7
7
  let(:config) { Yell::Configuration.load!(file) }
8
8
 
@@ -12,23 +12,23 @@ describe Yell::Configuration do
12
12
  it { should have_key(:level) }
13
13
  it { should have_key(:adapters) }
14
14
 
15
- context :level do
15
+ context ":level" do
16
16
  subject { config[:level] }
17
17
 
18
- it { should == "info" }
18
+ it { should eq("info") }
19
19
  end
20
20
 
21
- context :adapters do
21
+ context ":adapters" do
22
22
  subject { config[:adapters] }
23
23
 
24
24
  it { should be_kind_of(Array) }
25
25
 
26
26
  # stdout
27
- it { subject.first.should == :stdout }
27
+ it { expect(subject.first).to eq(:stdout) }
28
28
 
29
29
  # stderr
30
- it { subject.last.should be_kind_of(Hash) }
31
- it { subject.last.should == { :stderr => {:level => 'gte.error'} } }
30
+ it { expect(subject.last).to be_kind_of(Hash) }
31
+ it { expect(subject.last).to eq(:stderr => {:level => 'gte.error'}) }
32
32
  end
33
33
  end
34
34
 
@@ -20,39 +20,36 @@ describe Yell::Event do
20
20
  let(:logger) { Yell::Logger.new(:trace => true) }
21
21
  let(:event) { Yell::Event.new(logger, 1, 'Hello World!') }
22
22
 
23
- context :level do
23
+ context "#level" do
24
24
  subject { event.level }
25
- it { should == 1 }
25
+ it { should eq(1) }
26
26
  end
27
27
 
28
- context :messages do
28
+ context "#messages" do
29
29
  subject { event.messages }
30
- it { should == ['Hello World!'] }
30
+ it { should eq(['Hello World!']) }
31
31
  end
32
32
 
33
- context :time do
34
- subject { event.time.to_s }
35
-
33
+ context "#time" do
36
34
  let(:time) { Time.now }
35
+ subject { event.time.to_s }
37
36
 
38
- before do
39
- Timecop.freeze( time )
40
- end
37
+ before { Timecop.freeze(time) }
41
38
 
42
- it { should == time.to_s }
39
+ it { should eq(time.to_s) }
43
40
  end
44
41
 
45
- context :hostname do
42
+ context "#hostname" do
46
43
  subject { event.hostname }
47
- it { should == Socket.gethostname }
44
+ it { should eq(Socket.gethostname) }
48
45
  end
49
46
 
50
- context :pid do
47
+ context "#pid" do
51
48
  subject { event.pid }
52
- it { should == Process.pid }
49
+ it { should eq(Process.pid) }
53
50
  end
54
51
 
55
- context "pid when forked", :pending => RUBY_PLATFORM == 'java' do # no forking with jruby
52
+ context "#id when forked", :pending => RUBY_PLATFORM == 'java' ? "No forking with jruby" : false do
56
53
  subject { @pid }
57
54
 
58
55
  before do
@@ -69,31 +66,32 @@ describe Yell::Event do
69
66
  read.close
70
67
  end
71
68
 
72
- it { should_not == Process.pid }
73
- it { should == @child_pid }
69
+ it { should_not eq(Process.pid) }
70
+ it { should eq(@child_pid) }
74
71
  end
75
72
 
76
- context :progname do
73
+ context "#progname" do
77
74
  subject { event.progname }
78
- it { should == $0 }
75
+ it { should eq($0) }
79
76
  end
80
77
 
81
- context :caller do
78
+ context ":caller" do
82
79
  subject { EventFactory.event(logger, 1, "Hello World") }
83
80
 
84
81
  context "with trace" do
85
- its(:file) { should == __FILE__ }
86
- its(:line) { should == "8" }
87
- its(:method) { should == "event" }
82
+ its(:file) { should eq(__FILE__) }
83
+ its(:line) { should eq("8") }
84
+ its(:method) { should eq("event") }
88
85
  end
89
86
 
90
87
  context "without trace" do
91
88
  before { logger.trace = false }
92
89
 
93
- its(:file) { should == "" }
94
- its(:line) { should == "" }
95
- its(:method) { should == "" }
90
+ its(:file) { should eq("") }
91
+ its(:line) { should eq("") }
92
+ its(:method) { should eq("") }
96
93
  end
97
94
  end
98
95
 
99
96
  end
97
+
@@ -3,127 +3,134 @@ require 'spec_helper'
3
3
  describe Yell::Formatter do
4
4
 
5
5
  let(:logger) { Yell::Logger.new }
6
- let(:formatter) { Yell::Formatter.new(subject) }
7
6
  let(:event) { Yell::Event.new(logger, 1, 'Hello World!') }
8
7
  let(:time) { Time.now }
9
8
 
10
- let(:format) { formatter.format(event) }
9
+ let(:pattern) { "%m" }
10
+ let(:formatter) { Yell::Formatter.new(pattern) }
11
11
 
12
12
  before do
13
- Timecop.freeze( time )
13
+ Timecop.freeze(time)
14
14
  end
15
15
 
16
- context "%m" do
17
- subject { "%m" }
18
- it { format.should == event.messages.join(' ') }
19
- end
16
+ describe "#format" do
17
+ subject { formatter.format(event) }
20
18
 
21
- context "%l" do
22
- subject { "%l" }
23
- it { format.should == Yell::Severities[event.level][0,1] }
24
- end
19
+ context "%m" do
20
+ let(:pattern) { "%m" }
21
+ it { should eq(event.messages.join(' ')) }
22
+ end
25
23
 
26
- context "%L" do
27
- subject { "%L" }
28
- it { format.should == Yell::Severities[event.level] }
29
- end
24
+ context "%l" do
25
+ let(:pattern) { "%l" }
26
+ it { should eq(Yell::Severities[event.level][0,1]) }
27
+ end
30
28
 
31
- context "%d" do
32
- subject { "%d" }
33
- it { format.should == event.time.iso8601 }
34
- end
29
+ context "%L" do
30
+ let(:pattern) { "%L" }
31
+ it { should eq(Yell::Severities[event.level]) }
32
+ end
35
33
 
36
- context "%p" do
37
- subject { "%p" }
38
- it { format.should == event.pid.to_s }
39
- end
34
+ context "%d" do
35
+ let(:pattern) { "%d" }
36
+ it { should eq(event.time.iso8601) }
37
+ end
40
38
 
41
- context "%P" do
42
- subject { "%P" }
43
- it { format.should == event.progname }
44
- end
45
- context "%t" do
46
- subject { "%t" }
47
- it { format.should == event.thread_id.to_s }
48
- end
39
+ context "%p" do
40
+ let(:pattern) { "%p" }
41
+ it { should eq(event.pid.to_s) }
42
+ end
49
43
 
50
- context "%h" do
51
- subject { "%h" }
52
- it { format.should == event.hostname }
53
- end
44
+ context "%P" do
45
+ let(:pattern) { "%P" }
46
+ it { should eq(event.progname) }
47
+ end
48
+ context "%t" do
49
+ let(:pattern) { "%t" }
50
+ it { should eq(event.thread_id.to_s) }
51
+ end
54
52
 
55
- context "caller" do
56
- let(:_caller) { [nil, nil, "/path/to/file.rb:123:in `test_method'"] }
53
+ context "%h" do
54
+ let(:pattern) { "%h" }
55
+ it { should eq(event.hostname) }
56
+ end
57
57
 
58
- before do
59
- any_instance_of( Yell::Event ) do |e|
60
- stub(e).file { "/path/to/file.rb" }
61
- stub(e).line { "123" }
62
- stub(e).method { "test_method" }
58
+ context ":caller" do
59
+ let(:_caller) { [nil, nil, "/path/to/file.rb:123:in `test_method'"] }
60
+
61
+ before do
62
+ any_instance_of(Yell::Event) do |e|
63
+ stub(e).file { "/path/to/file.rb" }
64
+ stub(e).line { "123" }
65
+ stub(e).method { "test_method" }
66
+ end
63
67
  end
64
- end
65
68
 
66
- context "%F" do
67
- subject { "%F" }
68
- it { format.should == "/path/to/file.rb" }
69
- end
69
+ context "%F" do
70
+ let(:pattern) { "%F" }
71
+ it { should eq("/path/to/file.rb") }
72
+ end
70
73
 
71
- context "%f" do
72
- subject { "%f" }
73
- it { format.should == "file.rb" }
74
- end
74
+ context "%f" do
75
+ let(:pattern) { "%f" }
76
+ it { should eq("file.rb") }
77
+ end
75
78
 
76
- context "%M" do
77
- subject { "%M" }
78
- it { format.should == "test_method" }
79
- end
79
+ context "%M" do
80
+ let(:pattern) { "%M" }
81
+ it { should eq("test_method") }
82
+ end
80
83
 
81
- context "%n" do
82
- subject { "%n" }
83
- it { format.should == "123" }
84
+ context "%n" do
85
+ let(:pattern) { "%n" }
86
+ it { should eq("123") }
87
+ end
84
88
  end
85
89
  end
86
90
 
87
- context "NoFormat" do
88
- subject { Yell::NoFormat }
89
- it { format.should == "Hello World!" }
90
- end
91
+ describe "#format from presets" do
92
+ subject { formatter.format(event) }
91
93
 
92
- context "DefaultFormat" do
93
- subject { Yell::DefaultFormat }
94
- it { format.should == "#{time.iso8601} [ INFO] #{$$} : Hello World!" }
95
- end
94
+ context "NoFormat" do
95
+ let(:pattern) { Yell::NoFormat }
96
+ it { should eq("Hello World!") }
97
+ end
96
98
 
97
- context "BasicFormat" do
98
- subject { Yell::BasicFormat }
99
- it { format.should == "I, #{time.iso8601} : Hello World!" }
100
- end
99
+ context "DefaultFormat" do
100
+ let(:pattern) { Yell::DefaultFormat }
101
+ it { should eq("#{time.iso8601} [ INFO] #{$$} : Hello World!") }
102
+ end
103
+
104
+ context "BasicFormat" do
105
+ let(:pattern) { Yell::BasicFormat }
106
+ it { should eq("I, #{time.iso8601} : Hello World!") }
107
+ end
101
108
 
102
- context "ExtendedFormat" do
103
- subject { Yell::ExtendedFormat }
104
- it { format.should == "#{time.iso8601} [ INFO] #{$$} #{Socket.gethostname} : Hello World!" }
109
+ context "ExtendedFormat" do
110
+ let(:pattern) { Yell::ExtendedFormat }
111
+ it { should eq("#{time.iso8601} [ INFO] #{$$} #{Socket.gethostname} : Hello World!") }
112
+ end
105
113
  end
106
114
 
107
- context "Exceptions" do
115
+ describe "#format from exception" do
108
116
  let(:exception) { StandardError.new( "This is an Exception" ) }
109
117
  let(:event) { Yell::Event.new(logger, 1, exception) }
110
-
111
- subject { "%m" }
118
+ subject { formatter.format(event) }
112
119
 
113
120
  before do
114
- mock( exception ).backtrace.times(any_times) { ["backtrace"] }
121
+ mock(exception).backtrace.times(any_times) { ["backtrace"] }
115
122
  end
116
123
 
117
- it { format.should == "StandardError: This is an Exception\n\tbacktrace" }
124
+ it { should eq("StandardError: This is an Exception\n\tbacktrace") }
118
125
  end
119
126
 
120
- context "Hashes" do
127
+ describe "#format from hash messages" do
121
128
  let(:hash) { { :test => 'message' } }
122
129
  let(:event) { Yell::Event.new(logger, 1, hash) }
130
+ subject { formatter.format(event) }
123
131
 
124
- subject { "%m" }
125
-
126
- it { format.should == "test: message" }
132
+ it { should eq("test: message") }
127
133
  end
128
134
 
129
135
  end
136
+