lumberjack 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/MIT_LICENSE +20 -0
  2. data/README.rdoc +86 -0
  3. data/Rakefile +56 -0
  4. data/VERSION +1 -0
  5. data/lib/lumberjack.rb +39 -0
  6. data/lib/lumberjack/device.rb +26 -0
  7. data/lib/lumberjack/device/date_rolling_log_file.rb +58 -0
  8. data/lib/lumberjack/device/log_file.rb +18 -0
  9. data/lib/lumberjack/device/null.rb +15 -0
  10. data/lib/lumberjack/device/rolling_log_file.rb +109 -0
  11. data/lib/lumberjack/device/size_rolling_log_file.rb +58 -0
  12. data/lib/lumberjack/device/writer.rb +119 -0
  13. data/lib/lumberjack/formatter.rb +76 -0
  14. data/lib/lumberjack/formatter/exception_formatter.rb +12 -0
  15. data/lib/lumberjack/formatter/inspect_formatter.rb +10 -0
  16. data/lib/lumberjack/formatter/pretty_print_formatter.rb +23 -0
  17. data/lib/lumberjack/formatter/string_formatter.rb +10 -0
  18. data/lib/lumberjack/log_entry.rb +36 -0
  19. data/lib/lumberjack/logger.rb +302 -0
  20. data/lib/lumberjack/rack.rb +5 -0
  21. data/lib/lumberjack/rack/unit_of_work.rb +15 -0
  22. data/lib/lumberjack/severity.rb +23 -0
  23. data/lib/lumberjack/template.rb +71 -0
  24. data/spec/device/date_rolling_log_file_spec.rb +66 -0
  25. data/spec/device/date_rolling_log_file_spec.rbc +2118 -0
  26. data/spec/device/log_file_spec.rb +26 -0
  27. data/spec/device/log_file_spec.rbc +727 -0
  28. data/spec/device/null_spec.rb +12 -0
  29. data/spec/device/null_spec.rbc +362 -0
  30. data/spec/device/rolling_log_file_spec.rb +117 -0
  31. data/spec/device/rolling_log_file_spec.rbc +2894 -0
  32. data/spec/device/size_rolling_log_file_spec.rb +54 -0
  33. data/spec/device/size_rolling_log_file_spec.rbc +1961 -0
  34. data/spec/device/stream_spec.rbc +3310 -0
  35. data/spec/device/writer_spec.rb +118 -0
  36. data/spec/entry_spec.rbc +2333 -0
  37. data/spec/formatter/exception_formatter_spec.rb +20 -0
  38. data/spec/formatter/exception_formatter_spec.rbc +620 -0
  39. data/spec/formatter/inspect_formatter_spec.rb +13 -0
  40. data/spec/formatter/inspect_formatter_spec.rbc +360 -0
  41. data/spec/formatter/pretty_print_formatter_spec.rb +14 -0
  42. data/spec/formatter/pretty_print_formatter_spec.rbc +380 -0
  43. data/spec/formatter/string_formatter_spec.rb +12 -0
  44. data/spec/formatter/string_formatter_spec.rbc +314 -0
  45. data/spec/formatter_spec.rb +45 -0
  46. data/spec/formatter_spec.rbc +1431 -0
  47. data/spec/log_entry_spec.rb +69 -0
  48. data/spec/logger_spec.rb +390 -0
  49. data/spec/logger_spec.rbc +10043 -0
  50. data/spec/lumberjack_spec.rb +22 -0
  51. data/spec/lumberjack_spec.rbc +523 -0
  52. data/spec/rack/unit_of_work_spec.rb +26 -0
  53. data/spec/rack/unit_of_work_spec.rbc +697 -0
  54. data/spec/severity_spec.rb +23 -0
  55. data/spec/spec_helper.rb +16 -0
  56. data/spec/spec_helper.rbc +391 -0
  57. data/spec/template_spec.rb +34 -0
  58. data/spec/template_spec.rbc +1563 -0
  59. data/spec/unique_identifier_spec.rbc +329 -0
  60. metadata +128 -0
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lumberjack::Severity do
4
+
5
+ it "should convert a level to a label" do
6
+ Lumberjack::Severity.level_to_label(Lumberjack::Severity::DEBUG).should == "DEBUG"
7
+ Lumberjack::Severity.level_to_label(Lumberjack::Severity::INFO).should == "INFO"
8
+ Lumberjack::Severity.level_to_label(Lumberjack::Severity::WARN).should == "WARN"
9
+ Lumberjack::Severity.level_to_label(Lumberjack::Severity::ERROR).should == "ERROR"
10
+ Lumberjack::Severity.level_to_label(Lumberjack::Severity::FATAL).should == "FATAL"
11
+ Lumberjack::Severity.level_to_label(-1).should == "UNKNOWN"
12
+ end
13
+
14
+ it "should convert a label to a level" do
15
+ Lumberjack::Severity.label_to_level("DEBUG").should == Lumberjack::Severity::DEBUG
16
+ Lumberjack::Severity.label_to_level(:info).should == Lumberjack::Severity::INFO
17
+ Lumberjack::Severity.label_to_level(:warn).should == Lumberjack::Severity::WARN
18
+ Lumberjack::Severity.label_to_level("Error").should == Lumberjack::Severity::ERROR
19
+ Lumberjack::Severity.label_to_level("FATAL").should == Lumberjack::Severity::FATAL
20
+ Lumberjack::Severity.label_to_level("???").should == Lumberjack::Severity::UNKNOWN
21
+ end
22
+
23
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path("../../lib/lumberjack.rb", __FILE__)
2
+ require 'stringio'
3
+ require 'fileutils'
4
+
5
+ def tmp_dir
6
+ File.expand_path("../tmp", __FILE__)
7
+ end
8
+
9
+ def create_tmp_dir
10
+ FileUtils.rm_r(tmp_dir) if File.exist?(tmp_dir)
11
+ FileUtils.mkdir_p(tmp_dir)
12
+ end
13
+
14
+ def delete_tmp_dir
15
+ FileUtils.rm_r(tmp_dir)
16
+ end
@@ -0,0 +1,391 @@
1
+ !RBIX
2
+ 0
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 81
13
+ 5
14
+ 45
15
+ 0
16
+ 1
17
+ 7
18
+ 2
19
+ 64
20
+ 65
21
+ 49
22
+ 3
23
+ 0
24
+ 49
25
+ 4
26
+ 2
27
+ 47
28
+ 49
29
+ 5
30
+ 1
31
+ 15
32
+ 5
33
+ 7
34
+ 6
35
+ 64
36
+ 47
37
+ 49
38
+ 5
39
+ 1
40
+ 15
41
+ 5
42
+ 7
43
+ 7
44
+ 64
45
+ 47
46
+ 49
47
+ 5
48
+ 1
49
+ 15
50
+ 99
51
+ 7
52
+ 8
53
+ 7
54
+ 9
55
+ 65
56
+ 67
57
+ 49
58
+ 10
59
+ 0
60
+ 49
61
+ 11
62
+ 4
63
+ 15
64
+ 99
65
+ 7
66
+ 12
67
+ 7
68
+ 13
69
+ 65
70
+ 67
71
+ 49
72
+ 10
73
+ 0
74
+ 49
75
+ 11
76
+ 4
77
+ 15
78
+ 99
79
+ 7
80
+ 14
81
+ 7
82
+ 15
83
+ 65
84
+ 67
85
+ 49
86
+ 10
87
+ 0
88
+ 49
89
+ 11
90
+ 4
91
+ 15
92
+ 2
93
+ 11
94
+ I
95
+ 5
96
+ I
97
+ 0
98
+ I
99
+ 0
100
+ I
101
+ 0
102
+ n
103
+ p
104
+ 16
105
+ x
106
+ 4
107
+ File
108
+ n
109
+ s
110
+ 23
111
+ ../../lib/lumberjack.rb
112
+ x
113
+ 11
114
+ active_path
115
+ x
116
+ 11
117
+ expand_path
118
+ x
119
+ 7
120
+ require
121
+ s
122
+ 8
123
+ stringio
124
+ s
125
+ 9
126
+ fileutils
127
+ x
128
+ 7
129
+ tmp_dir
130
+ M
131
+ 1
132
+ n
133
+ n
134
+ x
135
+ 7
136
+ tmp_dir
137
+ i
138
+ 14
139
+ 45
140
+ 0
141
+ 1
142
+ 7
143
+ 2
144
+ 64
145
+ 65
146
+ 49
147
+ 3
148
+ 0
149
+ 49
150
+ 4
151
+ 2
152
+ 11
153
+ I
154
+ 3
155
+ I
156
+ 0
157
+ I
158
+ 0
159
+ I
160
+ 0
161
+ n
162
+ p
163
+ 5
164
+ x
165
+ 4
166
+ File
167
+ n
168
+ s
169
+ 6
170
+ ../tmp
171
+ x
172
+ 11
173
+ active_path
174
+ x
175
+ 11
176
+ expand_path
177
+ p
178
+ 5
179
+ I
180
+ -1
181
+ I
182
+ 5
183
+ I
184
+ 0
185
+ I
186
+ 6
187
+ I
188
+ e
189
+ x
190
+ 58
191
+ /Users/bdurand/dev/projects/lumberjack/spec/spec_helper.rb
192
+ p
193
+ 0
194
+ x
195
+ 17
196
+ method_visibility
197
+ x
198
+ 15
199
+ add_defn_method
200
+ x
201
+ 14
202
+ create_tmp_dir
203
+ M
204
+ 1
205
+ n
206
+ n
207
+ x
208
+ 14
209
+ create_tmp_dir
210
+ i
211
+ 34
212
+ 45
213
+ 0
214
+ 1
215
+ 5
216
+ 48
217
+ 2
218
+ 49
219
+ 3
220
+ 1
221
+ 9
222
+ 22
223
+ 45
224
+ 4
225
+ 5
226
+ 5
227
+ 48
228
+ 2
229
+ 49
230
+ 6
231
+ 1
232
+ 8
233
+ 23
234
+ 1
235
+ 15
236
+ 45
237
+ 4
238
+ 7
239
+ 5
240
+ 48
241
+ 2
242
+ 49
243
+ 8
244
+ 1
245
+ 11
246
+ I
247
+ 2
248
+ I
249
+ 0
250
+ I
251
+ 0
252
+ I
253
+ 0
254
+ n
255
+ p
256
+ 9
257
+ x
258
+ 4
259
+ File
260
+ n
261
+ x
262
+ 7
263
+ tmp_dir
264
+ x
265
+ 6
266
+ exist?
267
+ x
268
+ 9
269
+ FileUtils
270
+ n
271
+ x
272
+ 4
273
+ rm_r
274
+ n
275
+ x
276
+ 7
277
+ mkdir_p
278
+ p
279
+ 7
280
+ I
281
+ -1
282
+ I
283
+ 9
284
+ I
285
+ 0
286
+ I
287
+ a
288
+ I
289
+ 18
290
+ I
291
+ b
292
+ I
293
+ 22
294
+ x
295
+ 58
296
+ /Users/bdurand/dev/projects/lumberjack/spec/spec_helper.rb
297
+ p
298
+ 0
299
+ x
300
+ 14
301
+ delete_tmp_dir
302
+ M
303
+ 1
304
+ n
305
+ n
306
+ x
307
+ 14
308
+ delete_tmp_dir
309
+ i
310
+ 10
311
+ 45
312
+ 0
313
+ 1
314
+ 5
315
+ 48
316
+ 2
317
+ 49
318
+ 3
319
+ 1
320
+ 11
321
+ I
322
+ 2
323
+ I
324
+ 0
325
+ I
326
+ 0
327
+ I
328
+ 0
329
+ n
330
+ p
331
+ 4
332
+ x
333
+ 9
334
+ FileUtils
335
+ n
336
+ x
337
+ 7
338
+ tmp_dir
339
+ x
340
+ 4
341
+ rm_r
342
+ p
343
+ 5
344
+ I
345
+ -1
346
+ I
347
+ e
348
+ I
349
+ 0
350
+ I
351
+ f
352
+ I
353
+ a
354
+ x
355
+ 58
356
+ /Users/bdurand/dev/projects/lumberjack/spec/spec_helper.rb
357
+ p
358
+ 0
359
+ p
360
+ 13
361
+ I
362
+ 0
363
+ I
364
+ 1
365
+ I
366
+ 13
367
+ I
368
+ 2
369
+ I
370
+ 1c
371
+ I
372
+ 3
373
+ I
374
+ 25
375
+ I
376
+ 5
377
+ I
378
+ 33
379
+ I
380
+ 9
381
+ I
382
+ 41
383
+ I
384
+ e
385
+ I
386
+ 51
387
+ x
388
+ 58
389
+ /Users/bdurand/dev/projects/lumberjack/spec/spec_helper.rb
390
+ p
391
+ 0
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lumberjack::Template do
4
+
5
+ let(:time_string){ "2011-01-15T14:23:45.123" }
6
+ let(:time){ Time.parse(time_string) }
7
+ let(:entry){ Lumberjack::LogEntry.new(time, Lumberjack::Severity::INFO, "line 1#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3", "app", 12345, "ABCD") }
8
+
9
+ it "should format a log entry with a template string" do
10
+ template = Lumberjack::Template.new(":message - :severity, :time, :progname@:pid (:unit_of_work_id)")
11
+ template.call(entry).should == "line 1 - INFO, 2011-01-15T14:23:45.123, app@12345 (ABCD)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
12
+ end
13
+
14
+ it "should be able to specify the time format for log entries as microseconds" do
15
+ template = Lumberjack::Template.new(":message (:time)", :time_format => :microseconds)
16
+ template.call(entry).should == "line 1 (2011-01-15T14:23:45.123000)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
17
+ end
18
+
19
+ it "should be able to specify the time format for log entries as milliseconds" do
20
+ template = Lumberjack::Template.new(":message (:time)", :time_format => :milliseconds)
21
+ template.call(entry).should == "line 1 (2011-01-15T14:23:45.123)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
22
+ end
23
+
24
+ it "should be able to specify the time format for log entries with a custom format" do
25
+ template = Lumberjack::Template.new(":message (:time)", :time_format => "%m/%d/%Y, %I:%M:%S %p")
26
+ template.call(entry).should == "line 1 (01/15/2011, 02:23:45 PM)#{Lumberjack::LINE_SEPARATOR}line 2#{Lumberjack::LINE_SEPARATOR}line 3"
27
+ end
28
+
29
+ it "should be able to specify a template for additional lines in a message" do
30
+ template = Lumberjack::Template.new(":message (:time)", :additional_lines => " // :message")
31
+ template.call(entry).should == "line 1 (2011-01-15T14:23:45.123) // line 2 // line 3"
32
+ end
33
+
34
+ end