lumberjack 1.0.13 → 1.1.0

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 (49) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +74 -0
  3. data/README.md +92 -20
  4. data/VERSION +1 -1
  5. data/lib/lumberjack.rb +51 -16
  6. data/lib/lumberjack/context.rb +35 -0
  7. data/lib/lumberjack/device.rb +20 -6
  8. data/lib/lumberjack/device/date_rolling_log_file.rb +2 -2
  9. data/lib/lumberjack/device/log_file.rb +12 -1
  10. data/lib/lumberjack/device/multi.rb +46 -0
  11. data/lib/lumberjack/device/null.rb +0 -2
  12. data/lib/lumberjack/device/rolling_log_file.rb +2 -2
  13. data/lib/lumberjack/device/size_rolling_log_file.rb +1 -1
  14. data/lib/lumberjack/device/writer.rb +86 -55
  15. data/lib/lumberjack/formatter.rb +54 -18
  16. data/lib/lumberjack/formatter/date_time_formatter.rb +26 -0
  17. data/lib/lumberjack/formatter/id_formatter.rb +23 -0
  18. data/lib/lumberjack/formatter/object_formatter.rb +12 -0
  19. data/lib/lumberjack/formatter/structured_formatter.rb +31 -0
  20. data/lib/lumberjack/log_entry.rb +41 -16
  21. data/lib/lumberjack/logger.rb +168 -63
  22. data/lib/lumberjack/rack.rb +3 -2
  23. data/lib/lumberjack/rack/context.rb +18 -0
  24. data/lib/lumberjack/rack/request_id.rb +4 -4
  25. data/lib/lumberjack/severity.rb +11 -9
  26. data/lib/lumberjack/tags.rb +24 -0
  27. data/lib/lumberjack/template.rb +74 -32
  28. data/lumberjack.gemspec +35 -0
  29. metadata +48 -37
  30. data/Rakefile +0 -40
  31. data/spec/device/date_rolling_log_file_spec.rb +0 -73
  32. data/spec/device/log_file_spec.rb +0 -48
  33. data/spec/device/null_spec.rb +0 -12
  34. data/spec/device/rolling_log_file_spec.rb +0 -151
  35. data/spec/device/size_rolling_log_file_spec.rb +0 -58
  36. data/spec/device/writer_spec.rb +0 -118
  37. data/spec/formatter/exception_formatter_spec.rb +0 -20
  38. data/spec/formatter/inspect_formatter_spec.rb +0 -13
  39. data/spec/formatter/pretty_print_formatter_spec.rb +0 -14
  40. data/spec/formatter/string_formatter_spec.rb +0 -12
  41. data/spec/formatter_spec.rb +0 -45
  42. data/spec/log_entry_spec.rb +0 -69
  43. data/spec/logger_spec.rb +0 -411
  44. data/spec/lumberjack_spec.rb +0 -29
  45. data/spec/rack/request_id_spec.rb +0 -48
  46. data/spec/rack/unit_of_work_spec.rb +0 -26
  47. data/spec/severity_spec.rb +0 -23
  48. data/spec/spec_helper.rb +0 -32
  49. data/spec/template_spec.rb +0 -34
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumberjack::Formatter::ExceptionFormatter do
4
-
5
- it "should convert an exception without a backtrace to a string" do
6
- e = ArgumentError.new("not expected")
7
- formatter = Lumberjack::Formatter::ExceptionFormatter.new
8
- formatter.call(e).should == "ArgumentError: not expected"
9
- end
10
-
11
- it "should convert an exception with a backtrace to a string" do
12
- begin
13
- raise ArgumentError.new("not expected")
14
- rescue => e
15
- formatter = Lumberjack::Formatter::ExceptionFormatter.new
16
- formatter.call(e).should == "ArgumentError: not expected#{Lumberjack::LINE_SEPARATOR} #{e.backtrace.join(Lumberjack::LINE_SEPARATOR + ' ')}"
17
- end
18
- end
19
-
20
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumberjack::Formatter::InspectFormatter do
4
-
5
- it "should format objects as string by calling their inspect method" do
6
- formatter = Lumberjack::Formatter::InspectFormatter.new
7
- formatter.call("abc").should == "\"abc\""
8
- formatter.call(:test).should == ":test"
9
- formatter.call(1).should == "1"
10
- formatter.call([:a, 1, "b"]).should == [:a, 1, "b"].inspect
11
- end
12
-
13
- end
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumberjack::Formatter::PrettyPrintFormatter do
4
-
5
- it "should convert an object to a string using pretty print" do
6
- object = Object.new
7
- def object.pretty_print(q)
8
- q.text "woot!"
9
- end
10
- formatter = Lumberjack::Formatter::PrettyPrintFormatter.new
11
- formatter.call(object).should == "woot!"
12
- end
13
-
14
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumberjack::Formatter::StringFormatter do
4
-
5
- it "should format objects as string by calling their to_s method" do
6
- formatter = Lumberjack::Formatter::StringFormatter.new
7
- formatter.call("abc").should == "abc"
8
- formatter.call(:test).should == "test"
9
- formatter.call(1).should == "1"
10
- end
11
-
12
- end
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumberjack::Formatter do
4
-
5
- let(:formatter){ Lumberjack::Formatter.new }
6
-
7
- it "should have a default set of formatters" do
8
- formatter.format("abc").should == "abc"
9
- formatter.format([1, 2, 3]).should == "[1, 2, 3]"
10
- formatter.format(ArgumentError.new("boom")).should == "ArgumentError: boom"
11
- end
12
-
13
- it "should be able to add a formatter object for a class" do
14
- formatter.add(Numeric, lambda{|obj| "number: #{obj}"})
15
- formatter.format(10).should == "number: 10"
16
- end
17
-
18
- it "should be able to add a formatter block for a class" do
19
- formatter.add(Numeric){|obj| "number: #{obj}"}
20
- formatter.format(10).should == "number: 10"
21
- end
22
-
23
- it "should be able to remove a formatter for a class" do
24
- formatter.remove(String)
25
- formatter.format("abc").should == "\"abc\""
26
- end
27
-
28
- it "should be able to chain add and remove calls" do
29
- formatter.remove(String).should == formatter
30
- formatter.add(String, Lumberjack::Formatter::StringFormatter.new).should == formatter
31
- end
32
-
33
- it "should format an object based on the class hierarchy" do
34
- formatter.add(Numeric){|obj| "number: #{obj}"}
35
- formatter.add(Integer){|obj| "fixed number: #{obj}"}
36
- formatter.format(10).should == "fixed number: 10"
37
- formatter.format(10.1).should == "number: 10.1"
38
- end
39
-
40
- it "should have a default formatter" do
41
- formatter.remove(Object)
42
- formatter.format(:test).should == ":test"
43
- end
44
-
45
- end
@@ -1,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Lumberjack::LogEntry do
4
-
5
- it "should have a time" do
6
- t = Time.now
7
- entry = Lumberjack::LogEntry.new(t, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
8
- entry.time.should == t
9
- entry.time = t + 1
10
- entry.time.should == t + 1
11
- end
12
-
13
- it "should have a severity" do
14
- entry = Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
15
- entry.severity.should == Lumberjack::Severity::INFO
16
- entry.severity = Lumberjack::Severity::WARN
17
- entry.severity.should == Lumberjack::Severity::WARN
18
- end
19
-
20
- it "should convert a severity label to a numeric level" do
21
- entry = Lumberjack::LogEntry.new(Time.now, "INFO", "test", "app", 1500, "ABCD")
22
- entry.severity.should == Lumberjack::Severity::INFO
23
- end
24
-
25
- it "should get the severity as a string" do
26
- Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::DEBUG, "test", "app", 1500, nil).severity_label.should == "DEBUG"
27
- Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "test", "app", 1500, nil).severity_label.should == "INFO"
28
- Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::WARN, "test", "app", 1500, nil).severity_label.should == "WARN"
29
- Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::ERROR, "test", "app", 1500, nil).severity_label.should == "ERROR"
30
- Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::FATAL, "test", "app", 1500, nil).severity_label.should == "FATAL"
31
- Lumberjack::LogEntry.new(Time.now, -1, "test", "app", 1500, nil).severity_label.should == "UNKNOWN"
32
- Lumberjack::LogEntry.new(Time.now, 1000, "test", "app", 1500, nil).severity_label.should == "UNKNOWN"
33
- end
34
-
35
- it "should have a message" do
36
- entry = Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
37
- entry.message.should == "test"
38
- entry.message = "new message"
39
- entry.message.should == "new message"
40
- end
41
-
42
- it "should have a progname" do
43
- entry = Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
44
- entry.progname.should == "app"
45
- entry.progname = "prog"
46
- entry.progname.should == "prog"
47
- end
48
-
49
- it "should have a pid" do
50
- entry = Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
51
- entry.pid.should == 1500
52
- entry.pid = 150
53
- entry.pid.should == 150
54
- end
55
-
56
- it "should have a unit_of_work_id" do
57
- entry = Lumberjack::LogEntry.new(Time.now, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
58
- entry.unit_of_work_id.should == "ABCD"
59
- entry.unit_of_work_id = "1234"
60
- entry.unit_of_work_id.should == "1234"
61
- end
62
-
63
- it "should be converted to a string" do
64
- t = Time.parse("2011-01-29T12:15:32.001")
65
- entry = Lumberjack::LogEntry.new(t, Lumberjack::Severity::INFO, "test", "app", 1500, "ABCD")
66
- entry.to_s.should == "[2011-01-29T12:15:32.001 INFO app(1500) #ABCD] test"
67
- end
68
-
69
- end
@@ -1,411 +0,0 @@
1
- require 'spec_helper'
2
- require 'pathname'
3
-
4
- describe Lumberjack::Logger do
5
-
6
- context "initialization" do
7
-
8
- before :all do
9
- create_tmp_dir
10
- end
11
-
12
- after :all do
13
- delete_tmp_dir
14
- end
15
-
16
- it "should wrap an IO stream in a device" do
17
- output = StringIO.new
18
- logger = Lumberjack::Logger.new(output)
19
- logger.device.class.should == Lumberjack::Device::Writer
20
- end
21
-
22
- it "should have a formatter" do
23
- output = StringIO.new
24
- logger = Lumberjack::Logger.new(output)
25
- logger.formatter.should be
26
- end
27
-
28
- it "should open a file path in a device" do
29
- logger = Lumberjack::Logger.new(File.join(tmp_dir, "log_file_1.log"))
30
- logger.device.class.should == Lumberjack::Device::LogFile
31
- end
32
-
33
- it "should open a pathname in a device" do
34
- logger = Lumberjack::Logger.new(Pathname.new(File.join(tmp_dir, "log_file_1.log")))
35
- logger.device.class.should == Lumberjack::Device::LogFile
36
- end
37
-
38
- it "should use the null device if the stream is :null" do
39
- logger = Lumberjack::Logger.new(:null)
40
- logger.device.class.should == Lumberjack::Device::Null
41
- end
42
-
43
- it "should set the level with a numeric" do
44
- logger = Lumberjack::Logger.new(:null, :level => Lumberjack::Severity::WARN)
45
- logger.level.should == Lumberjack::Severity::WARN
46
- end
47
-
48
- it "should set the level with a level" do
49
- logger = Lumberjack::Logger.new(:null, :level => :warn)
50
- logger.level.should == Lumberjack::Severity::WARN
51
- end
52
-
53
- it "should default the level to INFO" do
54
- logger = Lumberjack::Logger.new(:null)
55
- logger.level.should == Lumberjack::Severity::INFO
56
- end
57
-
58
- it "should set the progname"do
59
- logger = Lumberjack::Logger.new(:null, :progname => "app")
60
- logger.progname.should == "app"
61
- end
62
-
63
- it "should create a thread to flush the device" do
64
- Thread.should_receive(:new)
65
- logger = Lumberjack::Logger.new(:null, :flush_seconds => 10)
66
- end
67
- end
68
-
69
- context "attributes" do
70
- it "should have a level" do
71
- logger = Lumberjack::Logger.new
72
- logger.level = Lumberjack::Severity::DEBUG
73
- logger.level.should == Lumberjack::Severity::DEBUG
74
- end
75
-
76
- it "should have a progname" do
77
- logger = Lumberjack::Logger.new
78
- logger.progname = "app"
79
- logger.progname.should == "app"
80
- end
81
-
82
- it "should be able to silence the log in a block" do
83
- output = StringIO.new
84
- logger = Lumberjack::Logger.new(output, :buffer_size => 0, :level => Lumberjack::Severity::INFO, :template => ":message")
85
- logger.info("one")
86
- logger.silence do
87
- logger.level.should == Lumberjack::Severity::ERROR
88
- logger.info("two")
89
- logger.error("three")
90
- end
91
- logger.info("four")
92
- output.string.split.should == ["one", "three", "four"]
93
- end
94
-
95
- it "should be able to customize the level of silence in a block" do
96
- output = StringIO.new
97
- logger = Lumberjack::Logger.new(output, :buffer_size => 0, :level => Lumberjack::Severity::INFO, :template => ":message")
98
- logger.info("one")
99
- logger.silence(Lumberjack::Severity::FATAL) do
100
- logger.level.should == Lumberjack::Severity::FATAL
101
- logger.info("two")
102
- logger.error("three")
103
- logger.fatal("woof")
104
- end
105
- logger.info("four")
106
- output.string.split.should == ["one", "woof", "four"]
107
- end
108
-
109
- it "should not be able to silence the logger if silencing is disabled" do
110
- output = StringIO.new
111
- logger = Lumberjack::Logger.new(output, :buffer_size => 0, :level => Lumberjack::Severity::INFO, :template => ":message")
112
- logger.silencer = false
113
- logger.info("one")
114
- logger.silence do
115
- logger.level.should == Lumberjack::Severity::INFO
116
- logger.info("two")
117
- logger.error("three")
118
- end
119
- logger.info("four")
120
- output.string.split.should == ["one", "two", "three", "four"]
121
- end
122
-
123
- it "should be able to set the progname in a block" do
124
- logger = Lumberjack::Logger.new
125
- logger.set_progname("app")
126
- logger.progname.should == "app"
127
- block_executed = false
128
- logger.set_progname("xxx") do
129
- block_executed = true
130
- logger.progname.should == "xxx"
131
- end
132
- block_executed.should == true
133
- logger.progname.should == "app"
134
- end
135
-
136
- it "should only affect the current thread when silencing the logger" do
137
- output = StringIO.new
138
- logger = Lumberjack::Logger.new(output, :buffer_size => 0, :level => Lumberjack::Severity::INFO, :template => ":message")
139
- # status is used to make sure the two threads are executing at the same time
140
- status = 0
141
- begin
142
- Thread.new do
143
- logger.silence do
144
- logger.info("inner")
145
- status = 1
146
- loop{ sleep(0.001); break if status == 2}
147
- end
148
- end
149
- loop{ sleep(0.001); break if status == 1}
150
- logger.info("outer")
151
- status = 2
152
- logger.close
153
- output.string.should include("outer")
154
- output.string.should_not include("inner")
155
- ensure
156
- status = 2
157
- end
158
- end
159
-
160
- it "should only affect the current thread when changing the progname in a block" do
161
- output = StringIO.new
162
- logger = Lumberjack::Logger.new(output, :progname => "thread1", :buffer_size => 0, :level => Lumberjack::Severity::INFO, :template => ":progname :message")
163
- # status is used to make sure the two threads are executing at the same time
164
- status = 0
165
- begin
166
- Thread.new do
167
- logger.set_progname("thread2") do
168
- logger.info("inner")
169
- status = 1
170
- loop{ sleep(0.001); break if status == 2}
171
- end
172
- end
173
- loop{ sleep(0.001); break if status == 1}
174
- logger.info("outer")
175
- status = 2
176
- logger.close
177
- output.string.should include("thread1")
178
- output.string.should include("thread2")
179
- ensure
180
- status = 2
181
- end
182
- end
183
- end
184
-
185
- context "flushing" do
186
- it "should autoflush the buffer if it hasn't been flushed in a specified number of seconds" do
187
- output = StringIO.new
188
- logger = Lumberjack::Logger.new(output, :flush_seconds => 0.1, :level => Lumberjack::Severity::INFO, :template => ":message", :buffer_size => 32767)
189
- logger.info("message 1")
190
- logger.info("message 2")
191
- output.string.should == ""
192
- sleep(0.15)
193
- output.string.split(Lumberjack::LINE_SEPARATOR).should == ["message 1", "message 2"]
194
- logger.info("message 3")
195
- output.string.should_not include("message 3")
196
- sleep(0.15)
197
- output.string.split(Lumberjack::LINE_SEPARATOR).should == ["message 1", "message 2", "message 3"]
198
- end
199
-
200
- it "should write the log entries to the device on flush and update the last flushed time" do
201
- output = StringIO.new
202
- logger = Lumberjack::Logger.new(output, :level => Lumberjack::Severity::INFO, :template => ":message", :buffer_size => 32767)
203
- logger.info("message 1")
204
- output.string.should == ""
205
- last_flushed_at = logger.last_flushed_at
206
- logger.flush
207
- output.string.split(Lumberjack::LINE_SEPARATOR).should == ["message 1"]
208
- logger.last_flushed_at.should >= last_flushed_at
209
- end
210
-
211
- it "should flush the buffer and close the devices" do
212
- output = StringIO.new
213
- logger = Lumberjack::Logger.new(output, :level => Lumberjack::Severity::INFO, :template => ":message", :buffer_size => 32767)
214
- logger.info("message 1")
215
- output.string.should == ""
216
- logger.close
217
- output.string.split(Lumberjack::LINE_SEPARATOR).should == ["message 1"]
218
- output.should be_closed
219
- end
220
- end
221
-
222
- context "logging" do
223
- let(:output){ StringIO.new }
224
- let(:device){ Lumberjack::Device::Writer.new(output, :buffer_size => 0) }
225
- let(:logger){ Lumberjack::Logger.new(device, :level => Lumberjack::Severity::INFO, :progname => "test") }
226
- let(:n){ Lumberjack::LINE_SEPARATOR }
227
-
228
- it "should add entries with a numeric severity and a message" do
229
- time = Time.parse("2011-01-30T12:31:56.123")
230
- Time.stub(:now => time)
231
- logger.add(Lumberjack::Severity::INFO, "test")
232
- output.string.should == "[2011-01-30T12:31:56.123 INFO test(#{$$}) #] test#{n}"
233
- end
234
-
235
- it "should add entries with a severity label" do
236
- time = Time.parse("2011-01-30T12:31:56.123")
237
- Time.stub(:now => time)
238
- logger.add(:info, "test")
239
- output.string.should == "[2011-01-30T12:31:56.123 INFO test(#{$$}) #] test#{n}"
240
- end
241
-
242
- it "should add entries with a custom progname and message" do
243
- time = Time.parse("2011-01-30T12:31:56.123")
244
- Time.stub(:now => time)
245
- logger.add(Lumberjack::Severity::INFO, "test", "app")
246
- output.string.should == "[2011-01-30T12:31:56.123 INFO app(#{$$}) #] test#{n}"
247
- end
248
-
249
- it "should add entries with a local progname and message" do
250
- time = Time.parse("2011-01-30T12:31:56.123")
251
- Time.stub(:now => time)
252
- logger.set_progname("block") do
253
- logger.add(Lumberjack::Severity::INFO, "test")
254
- end
255
- output.string.should == "[2011-01-30T12:31:56.123 INFO block(#{$$}) #] test#{n}"
256
- end
257
-
258
- it "should add entries with a progname but no message or block" do
259
- time = Time.parse("2011-01-30T12:31:56.123")
260
- Time.stub(:now => time)
261
- logger.set_progname("default") do
262
- logger.add(Lumberjack::Severity::INFO, nil, "message")
263
- end
264
- output.string.should == "[2011-01-30T12:31:56.123 INFO default(#{$$}) #] message#{n}"
265
- end
266
-
267
- it "should add entries with a block" do
268
- time = Time.parse("2011-01-30T12:31:56.123")
269
- Time.stub(:now => time)
270
- logger.add(Lumberjack::Severity::INFO){"test"}
271
- output.string.should == "[2011-01-30T12:31:56.123 INFO test(#{$$}) #] test#{n}"
272
- end
273
-
274
- it "should log entries (::Logger compatibility)" do
275
- time = Time.parse("2011-01-30T12:31:56.123")
276
- Time.stub(:now => time)
277
- logger.log(Lumberjack::Severity::INFO, "test")
278
- output.string.should == "[2011-01-30T12:31:56.123 INFO test(#{$$}) #] test#{n}"
279
- end
280
-
281
- it "should append messages with unknown severity to the log" do
282
- time = Time.parse("2011-01-30T12:31:56.123")
283
- Time.stub(:now => time)
284
- logger << "test"
285
- output.string.should == "[2011-01-30T12:31:56.123 UNKNOWN test(#{$$}) #] test#{n}"
286
- end
287
-
288
- it "should ouput entries to STDERR if they can't be written the the device" do
289
- stderr = $stderr
290
- $stderr = StringIO.new
291
- begin
292
- time = Time.parse("2011-01-30T12:31:56.123")
293
- Time.stub(:now => time)
294
- device.should_receive(:write).and_raise(StandardError.new("Cannot write to device"))
295
- logger.add(Lumberjack::Severity::INFO, "test")
296
- $stderr.string.should include("[2011-01-30T12:31:56.123 INFO test(#{$$})] test")
297
- $stderr.string.should include("StandardError: Cannot write to device")
298
- ensure
299
- $stderr = stderr
300
- end
301
- end
302
-
303
- context "log helper methods" do
304
- let(:device){ Lumberjack::Device::Writer.new(output, :buffer_size => 0, :template => ":message") }
305
-
306
- it "should only add messages whose severity is greater or equal to the logger level" do
307
- logger.add(Lumberjack::Severity::DEBUG, "debug")
308
- logger.add(Lumberjack::Severity::INFO, "info")
309
- logger.add(Lumberjack::Severity::ERROR, "error")
310
- output.string.should == "info#{n}error#{n}"
311
- end
312
-
313
- it "should only log fatal messages when the level is set to fatal" do
314
- logger.level = Lumberjack::Severity::FATAL
315
- logger.fatal("fatal")
316
- logger.fatal?.should == true
317
- logger.error("error")
318
- logger.error?.should == false
319
- logger.warn("warn")
320
- logger.warn?.should == false
321
- logger.info("info")
322
- logger.info?.should == false
323
- logger.debug("debug")
324
- logger.debug?.should == false
325
- logger.unknown("unknown")
326
- output.string.should == "fatal#{n}unknown#{n}"
327
- end
328
-
329
- it "should only log error messages and higher when the level is set to error" do
330
- logger.level = Lumberjack::Severity::ERROR
331
- logger.fatal("fatal")
332
- logger.fatal?.should == true
333
- logger.error("error")
334
- logger.error?.should == true
335
- logger.warn("warn")
336
- logger.warn?.should == false
337
- logger.info("info")
338
- logger.info?.should == false
339
- logger.debug("debug")
340
- logger.debug?.should == false
341
- logger.unknown("unknown")
342
- output.string.should == "fatal#{n}error#{n}unknown#{n}"
343
- end
344
-
345
- it "should only log warn messages and higher when the level is set to warn" do
346
- logger.level = Lumberjack::Severity::WARN
347
- logger.fatal("fatal")
348
- logger.fatal?.should == true
349
- logger.error("error")
350
- logger.error?.should == true
351
- logger.warn("warn")
352
- logger.warn?.should == true
353
- logger.info("info")
354
- logger.info?.should == false
355
- logger.debug("debug")
356
- logger.debug?.should == false
357
- logger.unknown("unknown")
358
- output.string.should == "fatal#{n}error#{n}warn#{n}unknown#{n}"
359
- end
360
-
361
- it "should only log info messages and higher when the level is set to info" do
362
- logger.level = Lumberjack::Severity::INFO
363
- logger.fatal("fatal")
364
- logger.fatal?.should == true
365
- logger.error("error")
366
- logger.error?.should == true
367
- logger.warn("warn")
368
- logger.warn?.should == true
369
- logger.info("info")
370
- logger.info?.should == true
371
- logger.debug("debug")
372
- logger.debug?.should == false
373
- logger.unknown("unknown")
374
- output.string.should == "fatal#{n}error#{n}warn#{n}info#{n}unknown#{n}"
375
- end
376
-
377
- it "should log all messages when the level is set to debug" do
378
- logger.level = Lumberjack::Severity::DEBUG
379
- logger.fatal("fatal")
380
- logger.fatal?.should == true
381
- logger.error("error")
382
- logger.error?.should == true
383
- logger.warn("warn")
384
- logger.warn?.should == true
385
- logger.info("info")
386
- logger.info?.should == true
387
- logger.debug("debug")
388
- logger.debug?.should == true
389
- logger.unknown("unknown")
390
- output.string.should == "fatal#{n}error#{n}warn#{n}info#{n}debug#{n}unknown#{n}"
391
- end
392
-
393
- it "should only log unkown messages when the level is set above fatal" do
394
- logger.level = Lumberjack::Severity::FATAL + 1
395
- logger.fatal("fatal")
396
- logger.fatal?.should == false
397
- logger.error("error")
398
- logger.error?.should == false
399
- logger.warn("warn")
400
- logger.warn?.should == false
401
- logger.info("info")
402
- logger.info?.should == false
403
- logger.debug("debug")
404
- logger.debug?.should == false
405
- logger.unknown("unknown")
406
- output.string.should == "unknown#{n}"
407
- end
408
- end
409
- end
410
-
411
- end