yell 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -1
- data/.travis.yml +1 -2
- data/Gemfile +5 -1
- data/README.md +67 -14
- data/examples/004.1-colorizing-the-log-output.rb +4 -4
- data/lib/yell.rb +19 -10
- data/lib/yell/adapters.rb +23 -26
- data/lib/yell/adapters/base.rb +8 -2
- data/lib/yell/adapters/datefile.rb +45 -42
- data/lib/yell/adapters/file.rb +10 -5
- data/lib/yell/adapters/io.rb +52 -48
- data/lib/yell/adapters/streams.rb +10 -2
- data/lib/yell/configuration.rb +1 -1
- data/lib/yell/event.rb +4 -4
- data/lib/yell/formatter.rb +11 -25
- data/lib/yell/helpers/adapters.rb +51 -0
- data/lib/yell/helpers/base.rb +19 -0
- data/lib/yell/helpers/formatter.rb +31 -0
- data/lib/yell/helpers/level.rb +36 -0
- data/lib/yell/helpers/silencer.rb +32 -0
- data/lib/yell/helpers/tracer.rb +48 -0
- data/lib/yell/level.rb +38 -47
- data/lib/yell/logger.rb +53 -73
- data/lib/yell/repository.rb +31 -29
- data/lib/yell/silencer.rb +69 -0
- data/lib/yell/version.rb +1 -1
- data/spec/spec_helper.rb +21 -9
- data/spec/yell/adapters/base_spec.rb +17 -34
- data/spec/yell/adapters/datefile_spec.rb +109 -66
- data/spec/yell/adapters/file_spec.rb +18 -18
- data/spec/yell/adapters/io_spec.rb +17 -13
- data/spec/yell/adapters/streams_spec.rb +7 -7
- data/spec/yell/adapters_spec.rb +18 -23
- data/spec/yell/configuration_spec.rb +7 -7
- data/spec/yell/event_spec.rb +25 -27
- data/spec/yell/formatter_spec.rb +89 -82
- data/spec/yell/level_spec.rb +119 -94
- data/spec/yell/loggable_spec.rb +6 -5
- data/spec/yell/logger_spec.rb +106 -66
- data/spec/yell/repository_spec.rb +23 -38
- data/spec/yell/silencer_spec.rb +49 -0
- data/spec/yell_spec.rb +24 -27
- 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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
41
|
+
|
42
|
+
expect(adapter.format).to eq(format)
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
|
-
context
|
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(
|
54
|
+
stub(adapter).stream { stream }
|
51
55
|
end
|
52
56
|
|
53
57
|
it "should format the message" do
|
54
|
-
mock.proxy(
|
58
|
+
mock.proxy(adapter.format).format( event )
|
55
59
|
|
56
|
-
adapter.write(
|
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(
|
65
|
+
mock(stream).syswrite( formatted << "\n" )
|
62
66
|
|
63
|
-
adapter.write(
|
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
|
5
|
+
it { should be_kind_of(Yell::Adapters::Io) }
|
6
6
|
|
7
|
-
context
|
7
|
+
context "#stream" do
|
8
8
|
subject { Yell::Adapters::Stdout.new.send :stream }
|
9
9
|
|
10
|
-
it { should be_kind_of
|
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
|
17
|
+
it { should be_kind_of(Yell::Adapters::Io) }
|
18
18
|
|
19
|
-
context
|
20
|
-
subject { Yell::Adapters::Stderr.new.send
|
19
|
+
context "#stream" do
|
20
|
+
subject { Yell::Adapters::Stderr.new.send(:stream) }
|
21
21
|
|
22
|
-
it { should be_kind_of
|
22
|
+
it { should be_kind_of(IO) }
|
23
23
|
end
|
24
24
|
|
25
25
|
end
|
data/spec/yell/adapters_spec.rb
CHANGED
@@ -2,46 +2,41 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Yell::Adapters do
|
4
4
|
|
5
|
-
context
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
Yell::Adapters.new( stdout ).should == stdout
|
11
|
-
end
|
10
|
+
expect(adapter).to eq(stdout)
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
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
|
-
|
19
|
-
end
|
16
|
+
Yell::Adapters.new(STDOUT)
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
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
|
-
|
27
|
-
end
|
22
|
+
Yell::Adapters.new(STDERR)
|
28
23
|
end
|
29
24
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
32
|
+
context ".register" do
|
38
33
|
let(:name) { :test }
|
39
34
|
let(:klass) { mock }
|
40
35
|
|
41
|
-
before { Yell::Adapters.register(
|
36
|
+
before { Yell::Adapters.register(name, klass) }
|
42
37
|
|
43
38
|
it "should allow to being called from :new" do
|
44
|
-
mock(
|
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 "
|
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
|
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.
|
27
|
+
it { expect(subject.first).to eq(:stdout) }
|
28
28
|
|
29
29
|
# stderr
|
30
|
-
it { subject.last.
|
31
|
-
it { subject.last.
|
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
|
|
data/spec/yell/event_spec.rb
CHANGED
@@ -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
|
23
|
+
context "#level" do
|
24
24
|
subject { event.level }
|
25
|
-
it { should
|
25
|
+
it { should eq(1) }
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
28
|
+
context "#messages" do
|
29
29
|
subject { event.messages }
|
30
|
-
it { should
|
30
|
+
it { should eq(['Hello World!']) }
|
31
31
|
end
|
32
32
|
|
33
|
-
context
|
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
|
39
|
-
Timecop.freeze( time )
|
40
|
-
end
|
37
|
+
before { Timecop.freeze(time) }
|
41
38
|
|
42
|
-
it { should
|
39
|
+
it { should eq(time.to_s) }
|
43
40
|
end
|
44
41
|
|
45
|
-
context
|
42
|
+
context "#hostname" do
|
46
43
|
subject { event.hostname }
|
47
|
-
it { should
|
44
|
+
it { should eq(Socket.gethostname) }
|
48
45
|
end
|
49
46
|
|
50
|
-
context
|
47
|
+
context "#pid" do
|
51
48
|
subject { event.pid }
|
52
|
-
it { should
|
49
|
+
it { should eq(Process.pid) }
|
53
50
|
end
|
54
51
|
|
55
|
-
context "
|
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
|
73
|
-
it { should
|
69
|
+
it { should_not eq(Process.pid) }
|
70
|
+
it { should eq(@child_pid) }
|
74
71
|
end
|
75
72
|
|
76
|
-
context
|
73
|
+
context "#progname" do
|
77
74
|
subject { event.progname }
|
78
|
-
it { should
|
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
|
86
|
-
its(:line) { should
|
87
|
-
its(:method) { should
|
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
|
+
|
data/spec/yell/formatter_spec.rb
CHANGED
@@ -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(:
|
9
|
+
let(:pattern) { "%m" }
|
10
|
+
let(:formatter) { Yell::Formatter.new(pattern) }
|
11
11
|
|
12
12
|
before do
|
13
|
-
Timecop.freeze(
|
13
|
+
Timecop.freeze(time)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
subject {
|
18
|
-
it { format.should == event.messages.join(' ') }
|
19
|
-
end
|
16
|
+
describe "#format" do
|
17
|
+
subject { formatter.format(event) }
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
context "%m" do
|
20
|
+
let(:pattern) { "%m" }
|
21
|
+
it { should eq(event.messages.join(' ')) }
|
22
|
+
end
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
context "%l" do
|
25
|
+
let(:pattern) { "%l" }
|
26
|
+
it { should eq(Yell::Severities[event.level][0,1]) }
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
context "%L" do
|
30
|
+
let(:pattern) { "%L" }
|
31
|
+
it { should eq(Yell::Severities[event.level]) }
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
context "%d" do
|
35
|
+
let(:pattern) { "%d" }
|
36
|
+
it { should eq(event.time.iso8601) }
|
37
|
+
end
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
53
|
+
context "%h" do
|
54
|
+
let(:pattern) { "%h" }
|
55
|
+
it { should eq(event.hostname) }
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
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
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
context "%F" do
|
70
|
+
let(:pattern) { "%F" }
|
71
|
+
it { should eq("/path/to/file.rb") }
|
72
|
+
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
context "%f" do
|
75
|
+
let(:pattern) { "%f" }
|
76
|
+
it { should eq("file.rb") }
|
77
|
+
end
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
79
|
+
context "%M" do
|
80
|
+
let(:pattern) { "%M" }
|
81
|
+
it { should eq("test_method") }
|
82
|
+
end
|
80
83
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
+
context "%n" do
|
85
|
+
let(:pattern) { "%n" }
|
86
|
+
it { should eq("123") }
|
87
|
+
end
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
87
|
-
|
88
|
-
subject {
|
89
|
-
it { format.should == "Hello World!" }
|
90
|
-
end
|
91
|
+
describe "#format from presets" do
|
92
|
+
subject { formatter.format(event) }
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
context "NoFormat" do
|
95
|
+
let(:pattern) { Yell::NoFormat }
|
96
|
+
it { should eq("Hello World!") }
|
97
|
+
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
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(
|
121
|
+
mock(exception).backtrace.times(any_times) { ["backtrace"] }
|
115
122
|
end
|
116
123
|
|
117
|
-
it {
|
124
|
+
it { should eq("StandardError: This is an Exception\n\tbacktrace") }
|
118
125
|
end
|
119
126
|
|
120
|
-
|
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
|
-
|
125
|
-
|
126
|
-
it { format.should == "test: message" }
|
132
|
+
it { should eq("test: message") }
|
127
133
|
end
|
128
134
|
|
129
135
|
end
|
136
|
+
|