yell 1.4.0 → 2.2.2
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.
- checksums.yaml +4 -4
- data/.gitignore +6 -2
- data/.ruby-version +1 -0
- data/.travis.yml +16 -13
- data/Gemfile +15 -8
- data/LICENSE.txt +1 -1
- data/README.md +10 -3
- data/Rakefile +1 -3
- data/examples/002.1-log-level-basics.rb +2 -2
- data/examples/002.2-log-level-on-certain-severities-only.rb +5 -4
- data/examples/002.3-log-level-within-range.rb +7 -5
- data/examples/003.1-formatting-DefaultFormat.rb +3 -3
- data/examples/003.2-formatting-BasicFormat.rb +3 -3
- data/examples/003.3-formatting-ExtendedFormat.rb +3 -3
- data/examples/003.4-formatting-on-your-own.rb +3 -3
- data/examples/004.1-colorizing-the-log-output.rb +3 -3
- data/examples/005.1-repository.rb +3 -3
- data/examples/006.1-the-loggable-module.rb +2 -2
- data/examples/006.2-the-loggable-module-with-inheritance.rb +2 -2
- data/lib/core_ext/logger.rb +17 -0
- data/lib/yell/adapters/base.rb +17 -22
- data/lib/yell/adapters/datefile.rb +23 -22
- data/lib/yell/adapters/file.rb +3 -7
- data/lib/yell/adapters/io.rb +9 -15
- data/lib/yell/adapters/streams.rb +0 -5
- data/lib/yell/adapters.rb +41 -10
- data/lib/yell/configuration.rb +2 -4
- data/lib/yell/event.rb +46 -10
- data/lib/yell/formatter.rb +134 -54
- data/lib/yell/helpers/{adapters.rb → adapter.rb} +7 -17
- data/lib/yell/helpers/base.rb +0 -1
- data/lib/yell/helpers/formatter.rb +8 -8
- data/lib/yell/helpers/level.rb +7 -4
- data/lib/yell/helpers/silencer.rb +3 -5
- data/lib/yell/helpers/tracer.rb +6 -7
- data/lib/yell/level.rb +19 -16
- data/lib/yell/loggable.rb +11 -7
- data/lib/yell/logger.rb +47 -68
- data/lib/yell/repository.rb +3 -5
- data/lib/yell/silencer.rb +30 -14
- data/lib/yell/version.rb +1 -4
- data/lib/yell.rb +29 -11
- data/yell.gemspec +22 -15
- metadata +19 -50
- data/spec/fixtures/yell.yml +0 -7
- data/spec/spec_helper.rb +0 -50
- data/spec/threaded/yell_spec.rb +0 -100
- data/spec/yell/adapters/base_spec.rb +0 -43
- data/spec/yell/adapters/datefile_spec.rb +0 -168
- data/spec/yell/adapters/file_spec.rb +0 -75
- data/spec/yell/adapters/io_spec.rb +0 -72
- data/spec/yell/adapters/streams_spec.rb +0 -26
- data/spec/yell/adapters_spec.rb +0 -45
- data/spec/yell/configuration_spec.rb +0 -36
- data/spec/yell/event_spec.rb +0 -97
- data/spec/yell/formatter_spec.rb +0 -136
- data/spec/yell/level_spec.rb +0 -200
- data/spec/yell/loggable_spec.rb +0 -20
- data/spec/yell/logger_spec.rb +0 -263
- data/spec/yell/repository_spec.rb +0 -70
- data/spec/yell/silencer_spec.rb +0 -49
- data/spec/yell_spec.rb +0 -102
data/spec/yell/logger_spec.rb
DELETED
@@ -1,263 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class LoggerFactory
|
4
|
-
attr_accessor :logger
|
5
|
-
|
6
|
-
def foo
|
7
|
-
logger.info :foo
|
8
|
-
end
|
9
|
-
|
10
|
-
def bar
|
11
|
-
logger.info :bar
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe Yell::Logger do
|
16
|
-
let(:filename) { fixture_path + '/logger.log' }
|
17
|
-
|
18
|
-
describe "a Logger instance" do
|
19
|
-
let(:logger) { Yell::Logger.new }
|
20
|
-
subject { logger }
|
21
|
-
|
22
|
-
its(:name) { should be_nil }
|
23
|
-
|
24
|
-
context "log methods" do
|
25
|
-
it { should respond_to(:debug) }
|
26
|
-
it { should respond_to(:debug?) }
|
27
|
-
|
28
|
-
it { should respond_to(:info) }
|
29
|
-
it { should respond_to(:info?) }
|
30
|
-
|
31
|
-
it { should respond_to(:warn) }
|
32
|
-
it { should respond_to(:warn?) }
|
33
|
-
|
34
|
-
it { should respond_to(:error) }
|
35
|
-
it { should respond_to(:error?) }
|
36
|
-
|
37
|
-
it { should respond_to(:fatal) }
|
38
|
-
it { should respond_to(:fatal?) }
|
39
|
-
|
40
|
-
it { should respond_to(:unknown) }
|
41
|
-
it { should respond_to(:unknown?) }
|
42
|
-
end
|
43
|
-
|
44
|
-
context "default #adapters" do
|
45
|
-
subject { logger.adapters }
|
46
|
-
|
47
|
-
its(:size) { should eq(1) }
|
48
|
-
its(:first) { should be_kind_of(Yell::Adapters::File) }
|
49
|
-
end
|
50
|
-
|
51
|
-
context "default #level" do
|
52
|
-
subject { logger.level }
|
53
|
-
|
54
|
-
it { should be_instance_of(Yell::Level) }
|
55
|
-
its(:severities) { should eq([true, true, true, true, true, true]) }
|
56
|
-
end
|
57
|
-
|
58
|
-
context "default #trace" do
|
59
|
-
subject { logger.trace }
|
60
|
-
|
61
|
-
it { should be_instance_of(Yell::Level) }
|
62
|
-
its(:severities) { should eq([false, false, false, true, true, true]) } # from error onwards
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
describe "initialize with #name" do
|
67
|
-
let(:name) { 'test' }
|
68
|
-
let!(:logger) { Yell.new(:name => name) }
|
69
|
-
|
70
|
-
it "should be added to the repository" do
|
71
|
-
expect(Yell::Repository[name]).to eq(logger)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context "initialize with #level" do
|
76
|
-
let(:level) { :error }
|
77
|
-
let(:logger) { Yell.new(:level => level) }
|
78
|
-
subject { logger.level }
|
79
|
-
|
80
|
-
it { should be_instance_of(Yell::Level) }
|
81
|
-
its(:severities) { should eq([false, false, false, true, true, true]) }
|
82
|
-
end
|
83
|
-
|
84
|
-
context "initialize with #trace" do
|
85
|
-
let(:trace) { :info }
|
86
|
-
let(:logger) { Yell.new(:trace => trace) }
|
87
|
-
subject { logger.trace }
|
88
|
-
|
89
|
-
it { should be_instance_of(Yell::Level) }
|
90
|
-
its(:severities) { should eq([false, true, true, true, true, true]) }
|
91
|
-
end
|
92
|
-
|
93
|
-
context "initialize with #silence" do
|
94
|
-
let(:silence) { "test" }
|
95
|
-
let(:logger) { Yell.new(:silence => silence) }
|
96
|
-
subject { logger.silencer }
|
97
|
-
|
98
|
-
it { should be_instance_of(Yell::Silencer) }
|
99
|
-
its(:patterns) { should eq([silence]) }
|
100
|
-
end
|
101
|
-
|
102
|
-
context "initialize with a #filename" do
|
103
|
-
it "should call adapter with :file" do
|
104
|
-
mock.proxy(Yell::Adapters::File).new(:filename => filename)
|
105
|
-
|
106
|
-
Yell::Logger.new(filename)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
context "initialize with a #filename of Pathname type" do
|
111
|
-
let(:pathname) { Pathname.new(filename) }
|
112
|
-
|
113
|
-
it "should call adapter with :file" do
|
114
|
-
mock.proxy(Yell::Adapters::File).new(:filename => pathname)
|
115
|
-
|
116
|
-
Yell::Logger.new(pathname)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "initialize with a :stdout adapter" do
|
121
|
-
before { mock.proxy(Yell::Adapters::Stdout).new(anything) }
|
122
|
-
|
123
|
-
it "should call adapter with STDOUT" do
|
124
|
-
Yell::Logger.new(STDOUT)
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should call adapter with :stdout" do
|
128
|
-
Yell::Logger.new(:stdout)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context "initialize with a :stderr adapter" do
|
133
|
-
before { mock.proxy(Yell::Adapters::Stderr).new(anything) }
|
134
|
-
|
135
|
-
it "should call adapter with STDERR" do
|
136
|
-
Yell::Logger.new(STDERR)
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should call adapter with :stderr" do
|
140
|
-
Yell::Logger.new(:stderr)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "initialize with a block" do
|
145
|
-
let(:level) { Yell::Level.new :error }
|
146
|
-
let(:stdout) { Yell::Adapters::Stdout.new }
|
147
|
-
let(:adapters) { loggr.instance_variable_get(:@adapters) }
|
148
|
-
|
149
|
-
context "with arity" do
|
150
|
-
subject do
|
151
|
-
Yell::Logger.new(:level => level) { |l| l.adapter(:stdout) }
|
152
|
-
end
|
153
|
-
|
154
|
-
its(:level) { should eq(level) }
|
155
|
-
its('adapters.size') { should eq(1) }
|
156
|
-
its('adapters.first') { should be_instance_of(Yell::Adapters::Stdout) }
|
157
|
-
end
|
158
|
-
|
159
|
-
context "without arity" do
|
160
|
-
subject do
|
161
|
-
Yell::Logger.new(:level => level) { adapter(:stdout) }
|
162
|
-
end
|
163
|
-
|
164
|
-
its(:level) { should eq(level) }
|
165
|
-
its('adapters.size') { should eq(1) }
|
166
|
-
its('adapters.first') { should be_instance_of(Yell::Adapters::Stdout) }
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "initialize with #adapters option" do
|
171
|
-
let(:logger) do
|
172
|
-
Yell::Logger.new(:adapters => [:stdout, {:stderr => {:level => :error}}])
|
173
|
-
end
|
174
|
-
|
175
|
-
let(:adapters) { logger.instance_variable_get(:@adapters) }
|
176
|
-
let(:stdout) { adapters.first }
|
177
|
-
let(:stderr) { adapters.last }
|
178
|
-
|
179
|
-
it "should define those adapters" do
|
180
|
-
expect(adapters.size).to eq(2)
|
181
|
-
|
182
|
-
expect(stdout).to be_kind_of(Yell::Adapters::Stdout)
|
183
|
-
expect(stderr).to be_kind_of(Yell::Adapters::Stderr)
|
184
|
-
end
|
185
|
-
|
186
|
-
it "should pass :level to :stderr adapter" do
|
187
|
-
expect(stderr.level.at?(:warn)).to be_false
|
188
|
-
expect(stderr.level.at?(:error)).to be_true
|
189
|
-
expect(stderr.level.at?(:fatal)).to be_true
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "caller's :file, :line and :method" do
|
194
|
-
let(:stdout) { Yell::Adapters::Stdout.new(:format => "%F, %n: %M") }
|
195
|
-
let(:logger) { Yell::Logger.new(:trace => true) { |l| l.adapter(stdout) } }
|
196
|
-
|
197
|
-
it "should write correctly" do
|
198
|
-
factory = LoggerFactory.new
|
199
|
-
factory.logger = logger
|
200
|
-
|
201
|
-
mock(stdout.send(:stream)).syswrite("#{__FILE__}, 7: foo\n")
|
202
|
-
mock(stdout.send(:stream)).syswrite("#{__FILE__}, 11: bar\n")
|
203
|
-
|
204
|
-
factory.foo
|
205
|
-
factory.bar
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context "logging in general" do
|
210
|
-
let(:logger) { Yell::Logger.new(filename, :format => "%m") }
|
211
|
-
let(:line) { File.open(filename, &:readline) }
|
212
|
-
|
213
|
-
it "should output a single message" do
|
214
|
-
logger.info "Hello World"
|
215
|
-
|
216
|
-
expect(line).to eq("Hello World\n")
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should output multiple messages" do
|
220
|
-
logger.info "Hello", "W", "o", "r", "l", "d"
|
221
|
-
|
222
|
-
expect(line).to eq("Hello W o r l d\n")
|
223
|
-
end
|
224
|
-
|
225
|
-
it "should output a hash and message" do
|
226
|
-
logger.info "Hello World", :test => :message
|
227
|
-
|
228
|
-
expect(line).to eq("Hello World test: message\n")
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should output a hash and message" do
|
232
|
-
logger.info( {:test => :message}, "Hello World" )
|
233
|
-
|
234
|
-
expect(line).to eq("test: message Hello World\n")
|
235
|
-
end
|
236
|
-
|
237
|
-
it "should output a hash and block" do
|
238
|
-
logger.info(:test => :message) { "Hello World" }
|
239
|
-
|
240
|
-
expect(line).to eq("test: message Hello World\n")
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
context "logging with a silencer" do
|
245
|
-
let(:silence) { "this" }
|
246
|
-
let(:stdout) { Yell::Adapters::Stdout.new }
|
247
|
-
let(:logger) { Yell::Logger.new(stdout, :silence => silence) }
|
248
|
-
|
249
|
-
it "should not pass a matching message to any adapter" do
|
250
|
-
dont_allow(stdout).write
|
251
|
-
|
252
|
-
logger.info "this should not be logged"
|
253
|
-
end
|
254
|
-
|
255
|
-
it "should pass a non-matching message to any adapter" do
|
256
|
-
mock(stdout).write(is_a(Yell::Event))
|
257
|
-
|
258
|
-
logger.info "that should be logged"
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
end
|
263
|
-
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell::Repository do
|
4
|
-
let(:name) { 'test' }
|
5
|
-
let(:logger) { Yell.new(:stdout) }
|
6
|
-
|
7
|
-
subject { Yell::Repository[name] }
|
8
|
-
|
9
|
-
context ".[]" do
|
10
|
-
it "should raise when not set" do
|
11
|
-
expect { subject }.to raise_error(Yell::LoggerNotFound)
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when logger with :name exists" do
|
15
|
-
let!(:logger) { Yell.new(:stdout, :name => name) }
|
16
|
-
|
17
|
-
it { should eq(logger) }
|
18
|
-
end
|
19
|
-
|
20
|
-
context "given a Class" do
|
21
|
-
let!(:logger) { Yell.new(:stdout, :name => "Numeric") }
|
22
|
-
|
23
|
-
it "should raise with the correct :name when logger not found" do
|
24
|
-
mock.proxy(Yell::LoggerNotFound).new(String)
|
25
|
-
lambda { Yell::Repository[String] }.should raise_error(Yell::LoggerNotFound)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return the logger" do
|
29
|
-
Yell::Repository[Numeric].should eq(logger)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should return the logger when superclass has it defined" do
|
33
|
-
Yell::Repository[Integer].should eq(logger)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context ".[]=" do
|
39
|
-
before { Yell::Repository[name] = logger }
|
40
|
-
it { should eq(logger) }
|
41
|
-
end
|
42
|
-
|
43
|
-
context ".[]= with a named logger" do
|
44
|
-
let!(:logger) { Yell.new(:stdout, :name => name) }
|
45
|
-
before { Yell::Repository[name] = logger }
|
46
|
-
|
47
|
-
it { should eq(logger) }
|
48
|
-
end
|
49
|
-
|
50
|
-
context ".[]= with a named logger of a different name" do
|
51
|
-
let(:other) { 'other' }
|
52
|
-
let(:logger) { Yell.new(:stdout, :name => other) }
|
53
|
-
before { Yell::Repository[name] = logger }
|
54
|
-
|
55
|
-
it "should add logger to both repositories" do
|
56
|
-
Yell::Repository[name].should eq(logger)
|
57
|
-
Yell::Repository[other].should eq(logger)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
context "loggers" do
|
62
|
-
let(:loggers) { { name => logger } }
|
63
|
-
subject { Yell::Repository.loggers }
|
64
|
-
before { Yell::Repository[name] = logger }
|
65
|
-
|
66
|
-
it { should eq(loggers) }
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
data/spec/yell/silencer_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell::Silencer do
|
4
|
-
|
5
|
-
context "initialize with #patterns" do
|
6
|
-
subject { Yell::Silencer.new(/this/) }
|
7
|
-
|
8
|
-
its(:patterns) { should eq([/this/]) }
|
9
|
-
end
|
10
|
-
|
11
|
-
context "#add" do
|
12
|
-
let(:silencer) { Yell::Silencer.new }
|
13
|
-
|
14
|
-
it "should add patterns" do
|
15
|
-
silencer.add /this/, /that/
|
16
|
-
|
17
|
-
expect(silencer.patterns).to eq([/this/, /that/])
|
18
|
-
end
|
19
|
-
|
20
|
-
it "should ignore duplicate patterns" do
|
21
|
-
silencer.add /this/, /that/, /this/
|
22
|
-
|
23
|
-
expect(silencer.patterns).to eq([/this/, /that/])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context "#silence?" do
|
28
|
-
let(:silencer) { Yell::Silencer.new }
|
29
|
-
|
30
|
-
it "should be false when no patterns present" do
|
31
|
-
expect(silencer.silence?).to be_false
|
32
|
-
end
|
33
|
-
|
34
|
-
it "should be true when patterns present" do
|
35
|
-
silencer.add /this/
|
36
|
-
|
37
|
-
expect(silencer.silence?).to be_true
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "#silence" do
|
42
|
-
let(:silencer) { Yell::Silencer.new(/this/) }
|
43
|
-
|
44
|
-
it "should reject messages that match any pattern" do
|
45
|
-
expect(silencer.silence("this", "that")).to eq(["that"])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
data/spec/yell_spec.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Yell do
|
4
|
-
let( :logger ) { Yell.new }
|
5
|
-
|
6
|
-
subject { logger }
|
7
|
-
|
8
|
-
it { should be_kind_of Yell::Logger }
|
9
|
-
|
10
|
-
it "should raise AdapterNotFound when adapter cant be loaded" do
|
11
|
-
expect {
|
12
|
-
Yell.new :unknownadapter
|
13
|
-
}.to raise_error(Yell::AdapterNotFound)
|
14
|
-
end
|
15
|
-
|
16
|
-
context ".level" do
|
17
|
-
subject { Yell.level }
|
18
|
-
it { should be_kind_of Yell::Level }
|
19
|
-
end
|
20
|
-
|
21
|
-
context ".format" do
|
22
|
-
subject { Yell.format( "%m" ) }
|
23
|
-
it { should be_kind_of Yell::Formatter }
|
24
|
-
end
|
25
|
-
|
26
|
-
context ".load!" do
|
27
|
-
subject { Yell.load!( 'yell.yml' ) }
|
28
|
-
|
29
|
-
before do
|
30
|
-
mock(Yell::Configuration).load!('yell.yml') { {} }
|
31
|
-
end
|
32
|
-
|
33
|
-
it { should be_kind_of Yell::Logger }
|
34
|
-
end
|
35
|
-
|
36
|
-
context ".[]" do
|
37
|
-
let(:name) { 'test' }
|
38
|
-
|
39
|
-
it "should delegate to the repository" do
|
40
|
-
mock(Yell::Repository)[name]
|
41
|
-
|
42
|
-
Yell[name]
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context ".[]=" do
|
47
|
-
let(:name) { 'test' }
|
48
|
-
|
49
|
-
it "should delegate to the repository" do
|
50
|
-
mock.proxy(Yell::Repository)[name] = logger
|
51
|
-
|
52
|
-
Yell[name] = logger
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context ".env" do
|
57
|
-
subject { Yell.env }
|
58
|
-
|
59
|
-
it "should default to YELL_ENV" do
|
60
|
-
subject.should == 'test'
|
61
|
-
end
|
62
|
-
|
63
|
-
context "fallback to RACK_ENV" do
|
64
|
-
before do
|
65
|
-
stub(ENV).key?('YELL_ENV') { false }
|
66
|
-
mock(ENV).key?('RACK_ENV') { true }
|
67
|
-
|
68
|
-
ENV['RACK_ENV'] = 'rack'
|
69
|
-
end
|
70
|
-
|
71
|
-
after { ENV.delete 'RACK_ENV' }
|
72
|
-
|
73
|
-
it { should == 'rack' }
|
74
|
-
end
|
75
|
-
|
76
|
-
context "fallback to RAILS_ENV" do
|
77
|
-
before do
|
78
|
-
stub(ENV).key?('YELL_ENV') { false }
|
79
|
-
stub(ENV).key?('RACK_ENV') { false }
|
80
|
-
mock(ENV).key?('RAILS_ENV') { true }
|
81
|
-
|
82
|
-
ENV['RAILS_ENV'] = 'rails'
|
83
|
-
end
|
84
|
-
|
85
|
-
after { ENV.delete 'RAILS_ENV' }
|
86
|
-
|
87
|
-
it { should == 'rails' }
|
88
|
-
end
|
89
|
-
|
90
|
-
context "fallback to development" do
|
91
|
-
before do
|
92
|
-
stub(ENV).key?('YELL_ENV') { false }
|
93
|
-
stub(ENV).key?('RACK_ENV') { false }
|
94
|
-
stub(ENV).key?('RAILS_ENV') { false }
|
95
|
-
end
|
96
|
-
|
97
|
-
it { should == 'development' }
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|