lumberjack 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT_LICENSE +20 -0
- data/README.rdoc +86 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/lib/lumberjack.rb +39 -0
- data/lib/lumberjack/device.rb +26 -0
- data/lib/lumberjack/device/date_rolling_log_file.rb +58 -0
- data/lib/lumberjack/device/log_file.rb +18 -0
- data/lib/lumberjack/device/null.rb +15 -0
- data/lib/lumberjack/device/rolling_log_file.rb +109 -0
- data/lib/lumberjack/device/size_rolling_log_file.rb +58 -0
- data/lib/lumberjack/device/writer.rb +119 -0
- data/lib/lumberjack/formatter.rb +76 -0
- data/lib/lumberjack/formatter/exception_formatter.rb +12 -0
- data/lib/lumberjack/formatter/inspect_formatter.rb +10 -0
- data/lib/lumberjack/formatter/pretty_print_formatter.rb +23 -0
- data/lib/lumberjack/formatter/string_formatter.rb +10 -0
- data/lib/lumberjack/log_entry.rb +36 -0
- data/lib/lumberjack/logger.rb +302 -0
- data/lib/lumberjack/rack.rb +5 -0
- data/lib/lumberjack/rack/unit_of_work.rb +15 -0
- data/lib/lumberjack/severity.rb +23 -0
- data/lib/lumberjack/template.rb +71 -0
- data/spec/device/date_rolling_log_file_spec.rb +66 -0
- data/spec/device/date_rolling_log_file_spec.rbc +2118 -0
- data/spec/device/log_file_spec.rb +26 -0
- data/spec/device/log_file_spec.rbc +727 -0
- data/spec/device/null_spec.rb +12 -0
- data/spec/device/null_spec.rbc +362 -0
- data/spec/device/rolling_log_file_spec.rb +117 -0
- data/spec/device/rolling_log_file_spec.rbc +2894 -0
- data/spec/device/size_rolling_log_file_spec.rb +54 -0
- data/spec/device/size_rolling_log_file_spec.rbc +1961 -0
- data/spec/device/stream_spec.rbc +3310 -0
- data/spec/device/writer_spec.rb +118 -0
- data/spec/entry_spec.rbc +2333 -0
- data/spec/formatter/exception_formatter_spec.rb +20 -0
- data/spec/formatter/exception_formatter_spec.rbc +620 -0
- data/spec/formatter/inspect_formatter_spec.rb +13 -0
- data/spec/formatter/inspect_formatter_spec.rbc +360 -0
- data/spec/formatter/pretty_print_formatter_spec.rb +14 -0
- data/spec/formatter/pretty_print_formatter_spec.rbc +380 -0
- data/spec/formatter/string_formatter_spec.rb +12 -0
- data/spec/formatter/string_formatter_spec.rbc +314 -0
- data/spec/formatter_spec.rb +45 -0
- data/spec/formatter_spec.rbc +1431 -0
- data/spec/log_entry_spec.rb +69 -0
- data/spec/logger_spec.rb +390 -0
- data/spec/logger_spec.rbc +10043 -0
- data/spec/lumberjack_spec.rb +22 -0
- data/spec/lumberjack_spec.rbc +523 -0
- data/spec/rack/unit_of_work_spec.rb +26 -0
- data/spec/rack/unit_of_work_spec.rbc +697 -0
- data/spec/severity_spec.rb +23 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/spec_helper.rbc +391 -0
- data/spec/template_spec.rb +34 -0
- data/spec/template_spec.rbc +1563 -0
- data/spec/unique_identifier_spec.rbc +329 -0
- metadata +128 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lumberjack::Device::Null do
|
4
|
+
|
5
|
+
it "should not generate any output" do
|
6
|
+
device = Lumberjack::Device::Null.new
|
7
|
+
device.write(Lumberjack::LogEntry.new(Time.now, 1, "New log entry", nil, $$, nil))
|
8
|
+
device.flush
|
9
|
+
device.close
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,362 @@
|
|
1
|
+
!RBIX
|
2
|
+
0
|
3
|
+
x
|
4
|
+
M
|
5
|
+
1
|
6
|
+
n
|
7
|
+
n
|
8
|
+
x
|
9
|
+
10
|
10
|
+
__script__
|
11
|
+
i
|
12
|
+
26
|
13
|
+
5
|
14
|
+
7
|
15
|
+
0
|
16
|
+
64
|
17
|
+
47
|
18
|
+
49
|
19
|
+
1
|
20
|
+
1
|
21
|
+
15
|
22
|
+
5
|
23
|
+
45
|
24
|
+
2
|
25
|
+
3
|
26
|
+
43
|
27
|
+
4
|
28
|
+
43
|
29
|
+
5
|
30
|
+
56
|
31
|
+
6
|
32
|
+
47
|
33
|
+
50
|
34
|
+
7
|
35
|
+
1
|
36
|
+
15
|
37
|
+
2
|
38
|
+
11
|
39
|
+
I
|
40
|
+
3
|
41
|
+
I
|
42
|
+
0
|
43
|
+
I
|
44
|
+
0
|
45
|
+
I
|
46
|
+
0
|
47
|
+
n
|
48
|
+
p
|
49
|
+
8
|
50
|
+
s
|
51
|
+
11
|
52
|
+
spec_helper
|
53
|
+
x
|
54
|
+
7
|
55
|
+
require
|
56
|
+
x
|
57
|
+
10
|
58
|
+
Lumberjack
|
59
|
+
n
|
60
|
+
x
|
61
|
+
6
|
62
|
+
Device
|
63
|
+
x
|
64
|
+
4
|
65
|
+
Null
|
66
|
+
M
|
67
|
+
1
|
68
|
+
p
|
69
|
+
2
|
70
|
+
x
|
71
|
+
9
|
72
|
+
for_block
|
73
|
+
t
|
74
|
+
n
|
75
|
+
x
|
76
|
+
9
|
77
|
+
__block__
|
78
|
+
i
|
79
|
+
11
|
80
|
+
5
|
81
|
+
7
|
82
|
+
0
|
83
|
+
64
|
84
|
+
56
|
85
|
+
1
|
86
|
+
47
|
87
|
+
50
|
88
|
+
2
|
89
|
+
1
|
90
|
+
11
|
91
|
+
I
|
92
|
+
4
|
93
|
+
I
|
94
|
+
0
|
95
|
+
I
|
96
|
+
0
|
97
|
+
I
|
98
|
+
0
|
99
|
+
I
|
100
|
+
-2
|
101
|
+
p
|
102
|
+
3
|
103
|
+
s
|
104
|
+
30
|
105
|
+
should not generate any output
|
106
|
+
M
|
107
|
+
1
|
108
|
+
p
|
109
|
+
2
|
110
|
+
x
|
111
|
+
9
|
112
|
+
for_block
|
113
|
+
t
|
114
|
+
n
|
115
|
+
x
|
116
|
+
9
|
117
|
+
__block__
|
118
|
+
i
|
119
|
+
115
|
120
|
+
45
|
121
|
+
0
|
122
|
+
1
|
123
|
+
43
|
124
|
+
2
|
125
|
+
43
|
126
|
+
3
|
127
|
+
13
|
128
|
+
71
|
129
|
+
4
|
130
|
+
47
|
131
|
+
9
|
132
|
+
25
|
133
|
+
47
|
134
|
+
49
|
135
|
+
5
|
136
|
+
0
|
137
|
+
13
|
138
|
+
47
|
139
|
+
49
|
140
|
+
6
|
141
|
+
0
|
142
|
+
15
|
143
|
+
8
|
144
|
+
28
|
145
|
+
49
|
146
|
+
4
|
147
|
+
0
|
148
|
+
19
|
149
|
+
0
|
150
|
+
15
|
151
|
+
20
|
152
|
+
0
|
153
|
+
45
|
154
|
+
0
|
155
|
+
7
|
156
|
+
43
|
157
|
+
8
|
158
|
+
13
|
159
|
+
71
|
160
|
+
4
|
161
|
+
47
|
162
|
+
9
|
163
|
+
76
|
164
|
+
47
|
165
|
+
49
|
166
|
+
5
|
167
|
+
0
|
168
|
+
13
|
169
|
+
45
|
170
|
+
9
|
171
|
+
10
|
172
|
+
49
|
173
|
+
11
|
174
|
+
0
|
175
|
+
79
|
176
|
+
7
|
177
|
+
12
|
178
|
+
64
|
179
|
+
1
|
180
|
+
99
|
181
|
+
43
|
182
|
+
13
|
183
|
+
7
|
184
|
+
14
|
185
|
+
49
|
186
|
+
15
|
187
|
+
1
|
188
|
+
1
|
189
|
+
47
|
190
|
+
49
|
191
|
+
6
|
192
|
+
6
|
193
|
+
15
|
194
|
+
8
|
195
|
+
99
|
196
|
+
45
|
197
|
+
9
|
198
|
+
16
|
199
|
+
49
|
200
|
+
11
|
201
|
+
0
|
202
|
+
79
|
203
|
+
7
|
204
|
+
12
|
205
|
+
64
|
206
|
+
1
|
207
|
+
99
|
208
|
+
43
|
209
|
+
13
|
210
|
+
7
|
211
|
+
14
|
212
|
+
49
|
213
|
+
15
|
214
|
+
1
|
215
|
+
1
|
216
|
+
49
|
217
|
+
4
|
218
|
+
6
|
219
|
+
49
|
220
|
+
17
|
221
|
+
1
|
222
|
+
15
|
223
|
+
20
|
224
|
+
0
|
225
|
+
49
|
226
|
+
18
|
227
|
+
0
|
228
|
+
15
|
229
|
+
20
|
230
|
+
0
|
231
|
+
49
|
232
|
+
19
|
233
|
+
0
|
234
|
+
11
|
235
|
+
I
|
236
|
+
b
|
237
|
+
I
|
238
|
+
1
|
239
|
+
I
|
240
|
+
0
|
241
|
+
I
|
242
|
+
0
|
243
|
+
I
|
244
|
+
-2
|
245
|
+
p
|
246
|
+
20
|
247
|
+
x
|
248
|
+
10
|
249
|
+
Lumberjack
|
250
|
+
n
|
251
|
+
x
|
252
|
+
6
|
253
|
+
Device
|
254
|
+
x
|
255
|
+
4
|
256
|
+
Null
|
257
|
+
x
|
258
|
+
3
|
259
|
+
new
|
260
|
+
x
|
261
|
+
8
|
262
|
+
allocate
|
263
|
+
x
|
264
|
+
10
|
265
|
+
initialize
|
266
|
+
n
|
267
|
+
x
|
268
|
+
5
|
269
|
+
Entry
|
270
|
+
x
|
271
|
+
4
|
272
|
+
Time
|
273
|
+
n
|
274
|
+
x
|
275
|
+
3
|
276
|
+
now
|
277
|
+
s
|
278
|
+
13
|
279
|
+
New log entry
|
280
|
+
x
|
281
|
+
7
|
282
|
+
Globals
|
283
|
+
x
|
284
|
+
2
|
285
|
+
$$
|
286
|
+
x
|
287
|
+
2
|
288
|
+
[]
|
289
|
+
n
|
290
|
+
x
|
291
|
+
5
|
292
|
+
write
|
293
|
+
x
|
294
|
+
5
|
295
|
+
flush
|
296
|
+
x
|
297
|
+
5
|
298
|
+
close
|
299
|
+
p
|
300
|
+
9
|
301
|
+
I
|
302
|
+
0
|
303
|
+
I
|
304
|
+
6
|
305
|
+
I
|
306
|
+
1f
|
307
|
+
I
|
308
|
+
7
|
309
|
+
I
|
310
|
+
67
|
311
|
+
I
|
312
|
+
8
|
313
|
+
I
|
314
|
+
6d
|
315
|
+
I
|
316
|
+
9
|
317
|
+
I
|
318
|
+
73
|
319
|
+
x
|
320
|
+
63
|
321
|
+
/Users/bdurand/dev/projects/lumberjack/spec/device/null_spec.rb
|
322
|
+
p
|
323
|
+
1
|
324
|
+
x
|
325
|
+
6
|
326
|
+
device
|
327
|
+
x
|
328
|
+
2
|
329
|
+
it
|
330
|
+
p
|
331
|
+
3
|
332
|
+
I
|
333
|
+
0
|
334
|
+
I
|
335
|
+
5
|
336
|
+
I
|
337
|
+
b
|
338
|
+
x
|
339
|
+
63
|
340
|
+
/Users/bdurand/dev/projects/lumberjack/spec/device/null_spec.rb
|
341
|
+
p
|
342
|
+
0
|
343
|
+
x
|
344
|
+
8
|
345
|
+
describe
|
346
|
+
p
|
347
|
+
5
|
348
|
+
I
|
349
|
+
0
|
350
|
+
I
|
351
|
+
1
|
352
|
+
I
|
353
|
+
9
|
354
|
+
I
|
355
|
+
3
|
356
|
+
I
|
357
|
+
1a
|
358
|
+
x
|
359
|
+
63
|
360
|
+
/Users/bdurand/dev/projects/lumberjack/spec/device/null_spec.rb
|
361
|
+
p
|
362
|
+
0
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Lumberjack::Device::RollingLogFile do
|
4
|
+
|
5
|
+
before :all do
|
6
|
+
create_tmp_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
after :all do
|
10
|
+
delete_tmp_dir
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:entry){ Lumberjack::LogEntry.new(Time.now, 1, "New log entry", nil, $$, nil) }
|
14
|
+
|
15
|
+
it "should check for rolling the log file on flush" do
|
16
|
+
device = Lumberjack::Device::RollingLogFile.new(File.join(tmp_dir, "test.log"))
|
17
|
+
device.write(entry)
|
18
|
+
device.should_receive(:roll_file?).twice.and_return(false)
|
19
|
+
device.flush
|
20
|
+
device.close
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should roll the file by archiving the existing file and opening a new stream and calling after_roll" do
|
24
|
+
log_file = File.join(tmp_dir, "test_2.log")
|
25
|
+
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message")
|
26
|
+
device.should_receive(:roll_file?).and_return(false, true)
|
27
|
+
device.should_receive(:after_roll)
|
28
|
+
device.stub!(:archive_file_suffix).and_return("rolled")
|
29
|
+
device.write(entry)
|
30
|
+
device.flush
|
31
|
+
device.write(Lumberjack::LogEntry.new(Time.now, 1, "Another log entry", nil, $$, nil))
|
32
|
+
device.close
|
33
|
+
File.read("#{log_file}.rolled").should == "New log entry#{Lumberjack::LINE_SEPARATOR}"
|
34
|
+
File.read(log_file).should == "Another log entry#{Lumberjack::LINE_SEPARATOR}"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should reopen the file if the stream inode doesn't match the file path inode" do
|
38
|
+
log_file = File.join(tmp_dir, "test_3.log")
|
39
|
+
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message")
|
40
|
+
device.stub!(:roll_file?).and_return(false)
|
41
|
+
device.write(entry)
|
42
|
+
device.flush
|
43
|
+
File.rename(log_file, "#{log_file}.rolled")
|
44
|
+
device.flush
|
45
|
+
device.write(Lumberjack::LogEntry.new(Time.now, 1, "Another log entry", nil, $$, nil))
|
46
|
+
device.close
|
47
|
+
File.read("#{log_file}.rolled").should == "New log entry#{Lumberjack::LINE_SEPARATOR}"
|
48
|
+
File.read(log_file).should == "Another log entry#{Lumberjack::LINE_SEPARATOR}"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should roll the file properly with multiple thread and processes using it" do
|
52
|
+
log_file = File.join(tmp_dir, "test_4.log")
|
53
|
+
process_count = 8
|
54
|
+
thread_count = 4
|
55
|
+
entry_count = 400
|
56
|
+
max_size = 128
|
57
|
+
severity = Lumberjack::Severity::INFO
|
58
|
+
message = "This is a test message that is written to the log file to indicate what the state of the application is."
|
59
|
+
|
60
|
+
process_count.times do
|
61
|
+
Process.fork do
|
62
|
+
device = Lumberjack::Device::SizeRollingLogFile.new(log_file, :max_size => max_size, :template => ":message")
|
63
|
+
threads = []
|
64
|
+
thread_count.times do
|
65
|
+
threads << Thread.new do
|
66
|
+
entry_count.times do |i|
|
67
|
+
device.write(Lumberjack::LogEntry.new(Time.now, severity, message, "test", $$, nil))
|
68
|
+
device.flush if i % 10 == 0
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
threads.each{|thread| thread.join}
|
73
|
+
device.close
|
74
|
+
end
|
75
|
+
end
|
76
|
+
Process.waitall
|
77
|
+
|
78
|
+
line_count = 0
|
79
|
+
file_count = 0
|
80
|
+
Dir.glob("#{log_file}*").each do |file|
|
81
|
+
file_count += 1
|
82
|
+
lines = File.read(file).split(Lumberjack::LINE_SEPARATOR)
|
83
|
+
line_count += lines.size
|
84
|
+
lines.each do |line|
|
85
|
+
line.should == message
|
86
|
+
end
|
87
|
+
unless file == log_file
|
88
|
+
File.size(file).should >= max_size
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
file_count.should > 3
|
93
|
+
line_count.should == process_count * thread_count * entry_count
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should only keep a specified number of archived log files" do
|
97
|
+
log_file = File.join(tmp_dir, "test_5.log")
|
98
|
+
device = Lumberjack::Device::RollingLogFile.new(log_file, :template => ":message", :keep => 2)
|
99
|
+
device.should_receive(:roll_file?).and_return(false, true, true, true)
|
100
|
+
device.stub!(:archive_file_suffix).and_return("delete", "another", "keep")
|
101
|
+
t = Time.now
|
102
|
+
File.should_receive(:ctime).with(log_file).any_number_of_times.and_return(t)
|
103
|
+
File.should_receive(:ctime).with("#{log_file}.delete").any_number_of_times.and_return(t + 1)
|
104
|
+
File.should_receive(:ctime).with("#{log_file}.another").any_number_of_times.and_return(t + 2)
|
105
|
+
File.should_receive(:ctime).with("#{log_file}.keep").any_number_of_times.and_return(t + 3)
|
106
|
+
device.write(entry)
|
107
|
+
device.flush
|
108
|
+
device.write(entry)
|
109
|
+
device.flush
|
110
|
+
device.write(entry)
|
111
|
+
device.flush
|
112
|
+
device.write(entry)
|
113
|
+
device.close
|
114
|
+
Dir.glob("#{log_file}*").sort.should == [log_file, "#{log_file}.another", "#{log_file}.keep"]
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|