yell 1.4.0 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -2
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +16 -13
  5. data/Gemfile +15 -8
  6. data/LICENSE.txt +1 -1
  7. data/README.md +10 -3
  8. data/Rakefile +1 -3
  9. data/examples/002.1-log-level-basics.rb +2 -2
  10. data/examples/002.2-log-level-on-certain-severities-only.rb +5 -4
  11. data/examples/002.3-log-level-within-range.rb +7 -5
  12. data/examples/003.1-formatting-DefaultFormat.rb +3 -3
  13. data/examples/003.2-formatting-BasicFormat.rb +3 -3
  14. data/examples/003.3-formatting-ExtendedFormat.rb +3 -3
  15. data/examples/003.4-formatting-on-your-own.rb +3 -3
  16. data/examples/004.1-colorizing-the-log-output.rb +3 -3
  17. data/examples/005.1-repository.rb +3 -3
  18. data/examples/006.1-the-loggable-module.rb +2 -2
  19. data/examples/006.2-the-loggable-module-with-inheritance.rb +2 -2
  20. data/lib/core_ext/logger.rb +17 -0
  21. data/lib/yell/adapters/base.rb +17 -22
  22. data/lib/yell/adapters/datefile.rb +23 -22
  23. data/lib/yell/adapters/file.rb +3 -7
  24. data/lib/yell/adapters/io.rb +9 -15
  25. data/lib/yell/adapters/streams.rb +0 -5
  26. data/lib/yell/adapters.rb +41 -10
  27. data/lib/yell/configuration.rb +2 -4
  28. data/lib/yell/event.rb +46 -10
  29. data/lib/yell/formatter.rb +134 -54
  30. data/lib/yell/helpers/{adapters.rb → adapter.rb} +7 -17
  31. data/lib/yell/helpers/base.rb +0 -1
  32. data/lib/yell/helpers/formatter.rb +8 -8
  33. data/lib/yell/helpers/level.rb +7 -4
  34. data/lib/yell/helpers/silencer.rb +3 -5
  35. data/lib/yell/helpers/tracer.rb +6 -7
  36. data/lib/yell/level.rb +19 -16
  37. data/lib/yell/loggable.rb +11 -7
  38. data/lib/yell/logger.rb +47 -68
  39. data/lib/yell/repository.rb +3 -5
  40. data/lib/yell/silencer.rb +30 -14
  41. data/lib/yell/version.rb +1 -4
  42. data/lib/yell.rb +29 -11
  43. data/yell.gemspec +22 -15
  44. metadata +19 -50
  45. data/spec/fixtures/yell.yml +0 -7
  46. data/spec/spec_helper.rb +0 -50
  47. data/spec/threaded/yell_spec.rb +0 -100
  48. data/spec/yell/adapters/base_spec.rb +0 -43
  49. data/spec/yell/adapters/datefile_spec.rb +0 -168
  50. data/spec/yell/adapters/file_spec.rb +0 -75
  51. data/spec/yell/adapters/io_spec.rb +0 -72
  52. data/spec/yell/adapters/streams_spec.rb +0 -26
  53. data/spec/yell/adapters_spec.rb +0 -45
  54. data/spec/yell/configuration_spec.rb +0 -36
  55. data/spec/yell/event_spec.rb +0 -97
  56. data/spec/yell/formatter_spec.rb +0 -136
  57. data/spec/yell/level_spec.rb +0 -200
  58. data/spec/yell/loggable_spec.rb +0 -20
  59. data/spec/yell/logger_spec.rb +0 -263
  60. data/spec/yell/repository_spec.rb +0 -70
  61. data/spec/yell/silencer_spec.rb +0 -49
  62. data/spec/yell_spec.rb +0 -102
@@ -1,26 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yell::Adapters::Stdout do
4
-
5
- it { should be_kind_of(Yell::Adapters::Io) }
6
-
7
- context "#stream" do
8
- subject { Yell::Adapters::Stdout.new.send :stream }
9
-
10
- it { should be_kind_of(IO) }
11
- end
12
-
13
- end
14
-
15
- describe Yell::Adapters::Stderr do
16
-
17
- it { should be_kind_of(Yell::Adapters::Io) }
18
-
19
- context "#stream" do
20
- subject { Yell::Adapters::Stderr.new.send(:stream) }
21
-
22
- it { should be_kind_of(IO) }
23
- end
24
-
25
- end
26
-
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yell::Adapters do
4
-
5
- context ".new" do
6
- it "should accept an adapter instance" do
7
- stdout = Yell::Adapters::Stdout.new
8
- adapter = Yell::Adapters.new(stdout)
9
-
10
- expect(adapter).to eq(stdout)
11
- end
12
-
13
- it "should accept STDOUT" do
14
- mock.proxy(Yell::Adapters::Stdout).new(anything)
15
-
16
- Yell::Adapters.new(STDOUT)
17
- end
18
-
19
- it "should accept STDERR" do
20
- mock.proxy(Yell::Adapters::Stderr).new(anything)
21
-
22
- Yell::Adapters.new(STDERR)
23
- end
24
-
25
- it "should raise an unregistered adapter" do
26
- expect {
27
- Yell::Adapters.new :unknown
28
- }.to raise_error(Yell::AdapterNotFound)
29
- end
30
- end
31
-
32
- context ".register" do
33
- let(:name) { :test }
34
- let(:klass) { mock }
35
-
36
- before { Yell::Adapters.register(name, klass) }
37
-
38
- it "should allow to being called from :new" do
39
- mock(klass).new(anything)
40
-
41
- Yell::Adapters.new(name)
42
- end
43
- end
44
-
45
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yell::Configuration do
4
-
5
- describe ".load!" do
6
- let(:file) { fixture_path + '/yell.yml' }
7
- let(:config) { Yell::Configuration.load!(file) }
8
-
9
- subject { config }
10
-
11
- it { should be_kind_of(Hash) }
12
- it { should have_key(:level) }
13
- it { should have_key(:adapters) }
14
-
15
- context ":level" do
16
- subject { config[:level] }
17
-
18
- it { should eq("info") }
19
- end
20
-
21
- context ":adapters" do
22
- subject { config[:adapters] }
23
-
24
- it { should be_kind_of(Array) }
25
-
26
- # stdout
27
- it { expect(subject.first).to eq(:stdout) }
28
-
29
- # stderr
30
- it { expect(subject.last).to be_kind_of(Hash) }
31
- it { expect(subject.last).to eq(:stderr => {:level => 'gte.error'}) }
32
- end
33
- end
34
-
35
- end
36
-
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Since Yell::Event.new is not called directly, but through
4
- # the logger methods, we need to divert here in order to get
5
- # the correct caller.
6
- class EventFactory
7
- def self.event(logger, level, message)
8
- self._event(logger, level, message)
9
- end
10
-
11
- private
12
-
13
- def self._event(logger, level, message)
14
- Yell::Event.new(logger, level, message)
15
- end
16
-
17
- end
18
-
19
- describe Yell::Event do
20
- let(:logger) { Yell::Logger.new(:trace => true) }
21
- let(:event) { Yell::Event.new(logger, 1, 'Hello World!') }
22
-
23
- context "#level" do
24
- subject { event.level }
25
- it { should eq(1) }
26
- end
27
-
28
- context "#messages" do
29
- subject { event.messages }
30
- it { should eq(['Hello World!']) }
31
- end
32
-
33
- context "#time" do
34
- let(:time) { Time.now }
35
- subject { event.time.to_s }
36
-
37
- before { Timecop.freeze(time) }
38
-
39
- it { should eq(time.to_s) }
40
- end
41
-
42
- context "#hostname" do
43
- subject { event.hostname }
44
- it { should eq(Socket.gethostname) }
45
- end
46
-
47
- context "#pid" do
48
- subject { event.pid }
49
- it { should eq(Process.pid) }
50
- end
51
-
52
- context "#id when forked", :pending => RUBY_PLATFORM == 'java' ? "No forking with jruby" : false do
53
- subject { @pid }
54
-
55
- before do
56
- read, write = IO.pipe
57
-
58
- @pid = Process.fork do
59
- event = Yell::Event.new(logger, 1, 'Hello World!')
60
- write.puts event.pid
61
- end
62
- Process.wait
63
- write.close
64
-
65
- @child_pid = read.read.to_i
66
- read.close
67
- end
68
-
69
- it { should_not eq(Process.pid) }
70
- it { should eq(@child_pid) }
71
- end
72
-
73
- context "#progname" do
74
- subject { event.progname }
75
- it { should eq($0) }
76
- end
77
-
78
- context ":caller" do
79
- subject { EventFactory.event(logger, 1, "Hello World") }
80
-
81
- context "with trace" do
82
- its(:file) { should eq(__FILE__) }
83
- its(:line) { should eq("8") }
84
- its(:method) { should eq("event") }
85
- end
86
-
87
- context "without trace" do
88
- before { logger.trace = false }
89
-
90
- its(:file) { should eq("") }
91
- its(:line) { should eq("") }
92
- its(:method) { should eq("") }
93
- end
94
- end
95
-
96
- end
97
-
@@ -1,136 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yell::Formatter do
4
-
5
- let(:logger) { Yell::Logger.new }
6
- let(:event) { Yell::Event.new(logger, 1, 'Hello World!') }
7
- let(:time) { Time.now }
8
-
9
- let(:pattern) { "%m" }
10
- let(:formatter) { Yell::Formatter.new(pattern) }
11
-
12
- before do
13
- Timecop.freeze(time)
14
- end
15
-
16
- describe "#format" do
17
- subject { formatter.format(event) }
18
-
19
- context "%m" do
20
- let(:pattern) { "%m" }
21
- it { should eq(event.messages.join(' ')) }
22
- end
23
-
24
- context "%l" do
25
- let(:pattern) { "%l" }
26
- it { should eq(Yell::Severities[event.level][0,1]) }
27
- end
28
-
29
- context "%L" do
30
- let(:pattern) { "%L" }
31
- it { should eq(Yell::Severities[event.level]) }
32
- end
33
-
34
- context "%d" do
35
- let(:pattern) { "%d" }
36
- it { should eq(event.time.iso8601) }
37
- end
38
-
39
- context "%p" do
40
- let(:pattern) { "%p" }
41
- it { should eq(event.pid.to_s) }
42
- end
43
-
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
52
-
53
- context "%h" do
54
- let(:pattern) { "%h" }
55
- it { should eq(event.hostname) }
56
- end
57
-
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
67
- end
68
-
69
- context "%F" do
70
- let(:pattern) { "%F" }
71
- it { should eq("/path/to/file.rb") }
72
- end
73
-
74
- context "%f" do
75
- let(:pattern) { "%f" }
76
- it { should eq("file.rb") }
77
- end
78
-
79
- context "%M" do
80
- let(:pattern) { "%M" }
81
- it { should eq("test_method") }
82
- end
83
-
84
- context "%n" do
85
- let(:pattern) { "%n" }
86
- it { should eq("123") }
87
- end
88
- end
89
- end
90
-
91
- describe "#format from presets" do
92
- subject { formatter.format(event) }
93
-
94
- context "NoFormat" do
95
- let(:pattern) { Yell::NoFormat }
96
- it { should eq("Hello World!") }
97
- end
98
-
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
108
-
109
- context "ExtendedFormat" do
110
- let(:pattern) { Yell::ExtendedFormat }
111
- it { should eq("#{time.iso8601} [ INFO] #{$$} #{Socket.gethostname} : Hello World!") }
112
- end
113
- end
114
-
115
- describe "#format from exception" do
116
- let(:exception) { StandardError.new( "This is an Exception" ) }
117
- let(:event) { Yell::Event.new(logger, 1, exception) }
118
- subject { formatter.format(event) }
119
-
120
- before do
121
- mock(exception).backtrace.times(any_times) { ["backtrace"] }
122
- end
123
-
124
- it { should eq("StandardError: This is an Exception\n\tbacktrace") }
125
- end
126
-
127
- describe "#format from hash messages" do
128
- let(:hash) { { :test => 'message' } }
129
- let(:event) { Yell::Event.new(logger, 1, hash) }
130
- subject { formatter.format(event) }
131
-
132
- it { should eq("test: message") }
133
- end
134
-
135
- end
136
-
@@ -1,200 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Yell::Level do
4
-
5
- context "default" do
6
- let(:level) { Yell::Level.new }
7
-
8
- it "should should return correctly" do
9
- expect(level.at?(:debug)).to be_true
10
- expect(level.at?(:info)).to be_true
11
- expect(level.at?(:warn)).to be_true
12
- expect(level.at?(:error)).to be_true
13
- expect(level.at?(:fatal)).to be_true
14
- end
15
- end
16
-
17
- context "given a Symbol" do
18
- let(:level) { Yell::Level.new(severity) }
19
-
20
- context ":debug" do
21
- let(:severity) { :debug }
22
-
23
- it "should should return correctly" do
24
- expect(level.at?(:debug)).to be_true
25
- expect(level.at?(:info)).to be_true
26
- expect(level.at?(:warn)).to be_true
27
- expect(level.at?(:error)).to be_true
28
- expect(level.at?(:fatal)).to be_true
29
- end
30
- end
31
-
32
- context ":info" do
33
- let(:severity) { :info }
34
-
35
- it "should should return correctly" do
36
- expect(level.at?(:debug)).to be_false
37
- expect(level.at?(:info)).to be_true
38
- expect(level.at?(:warn)).to be_true
39
- expect(level.at?(:error)).to be_true
40
- expect(level.at?(:fatal)).to be_true
41
- end
42
- end
43
-
44
- context ":warn" do
45
- let(:severity) { :warn }
46
-
47
- it "should should return correctly" do
48
- expect(level.at?(:debug)).to be_false
49
- expect(level.at?(:info)).to be_false
50
- expect(level.at?(:warn)).to be_true
51
- expect(level.at?(:error)).to be_true
52
- expect(level.at?(:fatal)).to be_true
53
- end
54
- end
55
-
56
- context ":error" do
57
- let(:severity) { :error }
58
-
59
- it "should should return correctly" do
60
- expect(level.at?(:debug)).to be_false
61
- expect(level.at?(:info)).to be_false
62
- expect(level.at?(:warn)).to be_false
63
- expect(level.at?(:error)).to be_true
64
- expect(level.at?(:fatal)).to be_true
65
- end
66
- end
67
-
68
- context ":fatal" do
69
- let(:severity) { :fatal }
70
-
71
- it "should should return correctly" do
72
- expect(level.at?(:debug)).to be_false
73
- expect(level.at?(:info)).to be_false
74
- expect(level.at?(:warn)).to be_false
75
- expect(level.at?(:error)).to be_false
76
- expect(level.at?(:fatal)).to be_true
77
- end
78
- end
79
- end
80
-
81
- context "given a String" do
82
- let(:level) { Yell::Level.new(severity) }
83
-
84
- context "basic string" do
85
- let(:severity) { 'error' }
86
-
87
- it "should should return correctly" do
88
- expect(level.at?(:debug)).to be_false
89
- expect(level.at?(:info)).to be_false
90
- expect(level.at?(:warn)).to be_false
91
- expect(level.at?(:error)).to be_true
92
- expect(level.at?(:fatal)).to be_true
93
- end
94
- end
95
-
96
- context "complex string with outer boundaries" do
97
- let(:severity) { 'gte.info lte.error' }
98
-
99
- it "should should return correctly" do
100
- expect(level.at?(:debug)).to be_false
101
- expect(level.at?(:info)).to be_true
102
- expect(level.at?(:warn)).to be_true
103
- expect(level.at?(:error)).to be_true
104
- expect(level.at?(:fatal)).to be_false
105
- end
106
- end
107
-
108
- context "complex string with inner boundaries" do
109
- let(:severity) { 'gt.info lt.error' }
110
-
111
- it "should be valid" do
112
- expect(level.at?(:debug)).to be_false
113
- expect(level.at?(:info)).to be_false
114
- expect(level.at?(:warn)).to be_true
115
- expect(level.at?(:error)).to be_false
116
- expect(level.at?(:fatal)).to be_false
117
- end
118
- end
119
-
120
- context "complex string with precise boundaries" do
121
- let(:severity) { 'at.info at.error' }
122
-
123
- it "should be valid" do
124
- expect(level.at?(:debug)).to be_false
125
- expect(level.at?(:info)).to be_true
126
- expect(level.at?(:warn)).to be_false
127
- expect(level.at?(:error)).to be_true
128
- expect(level.at?(:fatal)).to be_false
129
- end
130
- end
131
-
132
- context "complex string with combined boundaries" do
133
- let(:severity) { 'gte.error at.debug' }
134
-
135
- it "should be valid" do
136
- expect(level.at?(:debug)).to be_true
137
- expect(level.at?(:info)).to be_false
138
- expect(level.at?(:warn)).to be_false
139
- expect(level.at?(:error)).to be_true
140
- expect(level.at?(:fatal)).to be_true
141
- end
142
- end
143
- end
144
-
145
- context "given an Array" do
146
- let(:level) { Yell::Level.new( [:debug, :warn, :fatal] ) }
147
-
148
- it "should return correctly" do
149
- expect(level.at?(:debug)).to be_true
150
- expect(level.at?(:info)).to be_false
151
- expect(level.at?(:warn)).to be_true
152
- expect(level.at?(:error)).to be_false
153
- expect(level.at?(:fatal)).to be_true
154
- end
155
- end
156
-
157
- context "given a Range" do
158
- let(:level) { Yell::Level.new( (1..3) ) }
159
-
160
- it "should return correctly" do
161
- expect(level.at?(:debug)).to be_false
162
- expect(level.at?(:info)).to be_true
163
- expect(level.at?(:warn)).to be_true
164
- expect(level.at?(:error)).to be_true
165
- expect(level.at?(:fatal)).to be_false
166
- end
167
- end
168
-
169
- context "given a Yell::Level instance" do
170
- let(:level) { Yell::Level.new(:warn) }
171
-
172
- it "should return correctly" do
173
- expect(level.at?(:debug)).to be_false
174
- expect(level.at?(:info)).to be_false
175
- expect(level.at?(:warn)).to be_true
176
- expect(level.at?(:error)).to be_true
177
- expect(level.at?(:fatal)).to be_true
178
- end
179
- end
180
-
181
- context "backwards compatibility" do
182
- let(:level) { Yell::Level.new :warn }
183
-
184
- it "should return correctly to :to_i" do
185
- expect(level.to_i).to eq(2)
186
- end
187
-
188
- it "should typecast with Integer correctly" do
189
- expect(Integer(level)).to eq(2)
190
- end
191
-
192
- it "should be compatible when passing to array (https://github.com/rudionrails/yell/issues/1)" do
193
- severities = %w(FINE INFO WARNING SEVERE SEVERE INFO)
194
-
195
- expect(severities[level]).to eq("WARNING")
196
- end
197
- end
198
-
199
- end
200
-
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class LoggableFactory
4
- include Yell::Loggable
5
- end
6
-
7
- describe Yell::Loggable do
8
- let(:factory) { LoggableFactory.new }
9
- subject { factory }
10
-
11
- it { should respond_to(:logger) }
12
-
13
- it "should make a lookup in the Yell::Repository" do
14
- mock(Yell::Repository)[LoggableFactory]
15
-
16
- factory.logger
17
- end
18
-
19
- end
20
-