sawmill 0.1.15 → 0.1.16

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 (53) hide show
  1. data/History.rdoc +7 -0
  2. data/Version +1 -1
  3. data/lib/sawmill.rb +6 -6
  4. data/lib/sawmill/entry.rb +108 -108
  5. data/lib/sawmill/entry_classifier.rb +19 -19
  6. data/lib/sawmill/entry_processor.rb +63 -63
  7. data/lib/sawmill/entry_processor/build_records.rb +39 -39
  8. data/lib/sawmill/entry_processor/compile_report.rb +32 -32
  9. data/lib/sawmill/entry_processor/conditionals.rb +110 -110
  10. data/lib/sawmill/entry_processor/count_entries.rb +27 -27
  11. data/lib/sawmill/entry_processor/filter_by_basic_fields.rb +32 -32
  12. data/lib/sawmill/entry_processor/filter_by_block.rb +28 -28
  13. data/lib/sawmill/entry_processor/format.rb +41 -36
  14. data/lib/sawmill/entry_processor/interpret_stats.rb +24 -24
  15. data/lib/sawmill/entry_processor/simple_queue.rb +38 -38
  16. data/lib/sawmill/errors.rb +28 -28
  17. data/lib/sawmill/interface.rb +51 -51
  18. data/lib/sawmill/level.rb +75 -75
  19. data/lib/sawmill/log_record_middleware.rb +21 -21
  20. data/lib/sawmill/logger.rb +94 -94
  21. data/lib/sawmill/multi_parser.rb +28 -28
  22. data/lib/sawmill/parser.rb +32 -32
  23. data/lib/sawmill/railtie.rb +31 -31
  24. data/lib/sawmill/record.rb +74 -74
  25. data/lib/sawmill/record_processor.rb +54 -54
  26. data/lib/sawmill/record_processor/compile_report.rb +32 -32
  27. data/lib/sawmill/record_processor/conditionals.rb +92 -92
  28. data/lib/sawmill/record_processor/count_records.rb +24 -24
  29. data/lib/sawmill/record_processor/decompose.rb +21 -21
  30. data/lib/sawmill/record_processor/filter_by_attributes.rb +22 -22
  31. data/lib/sawmill/record_processor/filter_by_block.rb +29 -29
  32. data/lib/sawmill/record_processor/filter_by_record_id.rb +22 -22
  33. data/lib/sawmill/record_processor/format.rb +24 -24
  34. data/lib/sawmill/record_processor/simple_queue.rb +44 -44
  35. data/lib/sawmill/rotater.rb +60 -60
  36. data/lib/sawmill/rotater/base.rb +28 -28
  37. data/lib/sawmill/rotater/date_based_log_file.rb +50 -50
  38. data/lib/sawmill/rotater/shifting_log_file.rb +34 -34
  39. data/lib/sawmill/stats_middleware.rb +21 -21
  40. data/lib/sawmill/stats_railtie.rb +33 -33
  41. data/lib/sawmill/util/heap.rb +41 -41
  42. data/lib/sawmill/util/processor_tools.rb +17 -17
  43. data/lib/sawmill/util/queue.rb +33 -33
  44. data/lib/sawmill/version.rb +9 -9
  45. data/test/tc_entry_processors.rb +27 -27
  46. data/test/tc_formatter_parser.rb +40 -40
  47. data/test/tc_levels.rb +27 -27
  48. data/test/tc_logger.rb +49 -49
  49. data/test/tc_multi_parser.rb +18 -18
  50. data/test/tc_record_processors.rb +21 -21
  51. data/test/tc_records.rb +39 -39
  52. data/test/tc_reports.rb +19 -19
  53. metadata +10 -5
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor that formats for log files
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,23 +35,23 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # This processor formats log records and writes them to a destination.
43
-
43
+
44
44
  class Format < Base
45
-
46
-
45
+
46
+
47
47
  # Create a formatter.
48
- #
48
+ #
49
49
  # The destination can be a ruby IO object, a Sawmill::Rotater, or any
50
50
  # object that responds to the "write" and "close" methods as defined
51
51
  # by the ruby IO class.
52
- #
52
+ #
53
53
  # Recognized options include:
54
- #
54
+ #
55
55
  # [<tt>:include_id</tt>]
56
56
  # Include the record ID in every log entry. Default is false.
57
57
  # [<tt>:fractional_second_digits</tt>]
@@ -62,7 +62,7 @@ module Sawmill
62
62
  # [<tt>:entry_length_limit</tt>]
63
63
  # Limit to the entry length. Entries are truncated to this length
64
64
  # when written. If not specified, entries are not truncated.
65
-
65
+
66
66
  def initialize(destination_, opts_={})
67
67
  if (entry_length_limit_ = opts_.delete(:entry_length_limit))
68
68
  opts_ = opts_.merge(:length_limit => entry_length_limit_)
@@ -70,25 +70,25 @@ module Sawmill
70
70
  @formatter = EntryProcessor::Format.new(destination_, opts_)
71
71
  @classifier = EntryClassifier.new(@formatter)
72
72
  end
73
-
74
-
73
+
74
+
75
75
  def record(record_)
76
76
  record_.each_entry{ |entry_| @classifier.entry(entry_) }
77
77
  true
78
78
  end
79
-
79
+
80
80
  def extra_entry(entry_)
81
81
  @classifier.entry(entry_)
82
82
  true
83
83
  end
84
-
84
+
85
85
  def finish
86
86
  @formatter.finish
87
87
  end
88
-
88
+
89
89
  end
90
-
91
-
90
+
91
+
92
92
  end
93
-
93
+
94
94
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor queues log records
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -35,21 +35,21 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
39
-
38
+
39
+
40
40
  module RecordProcessor
41
-
42
-
41
+
42
+
43
43
  # This processor simply queues up log records for later use.
44
-
44
+
45
45
  class SimpleQueue < Base
46
-
47
-
46
+
47
+
48
48
  # Create a queue. This processor actually maintains two separate
49
49
  # queues, one for records and another for extra entries.
50
- #
50
+ #
51
51
  # Recognized options include:
52
- #
52
+ #
53
53
  # [<tt>:limit</tt>]
54
54
  # Size limit for the queue. If not specified, the queue can grow
55
55
  # arbitrarily large.
@@ -57,76 +57,76 @@ module Sawmill
57
57
  # If set to true, then when an item is added to a full queue, the
58
58
  # oldest item is dropped. If set to false or not specified, then
59
59
  # the new item is not added.
60
-
60
+
61
61
  def initialize(opts_={})
62
62
  @queue = Util::Queue.new(opts_)
63
63
  @extra_entries_queue = Util::Queue.new(opts_)
64
64
  @closed = false
65
65
  end
66
-
67
-
66
+
67
+
68
68
  # Return the oldest record in the record queue, or nil if the record
69
69
  # queue is empty.
70
-
70
+
71
71
  def dequeue
72
72
  @queue.dequeue
73
73
  end
74
-
75
-
74
+
75
+
76
76
  # Return an array of the contents of the record queue, in order.
77
-
77
+
78
78
  def dequeue_all
79
79
  @queue.dequeue_all
80
80
  end
81
-
82
-
81
+
82
+
83
83
  # Return the number of records in the record queue.
84
-
84
+
85
85
  def size
86
86
  @queue.size
87
87
  end
88
-
89
-
88
+
89
+
90
90
  # Return the oldest entry in the extra entry queue, or nil if the
91
91
  # extra entry queue is empty.
92
-
92
+
93
93
  def dequeue_extra_entry
94
94
  @extra_entries_queue.dequeue
95
95
  end
96
-
97
-
96
+
97
+
98
98
  # Return an array of the contents of the extra entry queue, in order.
99
-
99
+
100
100
  def dequeue_all_extra_entries
101
101
  @extra_entries_queue.dequeue_all
102
102
  end
103
-
104
-
103
+
104
+
105
105
  # Return the number of entries in the extra entry queue.
106
-
106
+
107
107
  def extra_entries_size
108
108
  @extra_entries_queue.size
109
109
  end
110
-
111
-
110
+
111
+
112
112
  def record(record_)
113
113
  @queue.enqueue(record_) unless @closed
114
114
  end
115
-
115
+
116
116
  def extra_entry(entry_)
117
117
  @extra_entries_queue.enqueue(entry_) unless @closed
118
118
  end
119
-
119
+
120
120
  def finish
121
121
  @closed = true
122
122
  nil
123
123
  end
124
-
125
-
124
+
125
+
126
126
  end
127
-
128
-
127
+
128
+
129
129
  end
130
-
131
-
130
+
131
+
132
132
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill log rotation utility
4
- #
4
+ #
5
5
  # -----------------------------------------------------------------------------
6
6
  # Copyright 2009 Daniel Azuma
7
- #
7
+ #
8
8
  # All rights reserved.
9
- #
9
+ #
10
10
  # Redistribution and use in source and binary forms, with or without
11
11
  # modification, are permitted provided that the following conditions are met:
12
- #
12
+ #
13
13
  # * Redistributions of source code must retain the above copyright notice,
14
14
  # this list of conditions and the following disclaimer.
15
15
  # * Redistributions in binary form must reproduce the above copyright notice,
@@ -18,7 +18,7 @@
18
18
  # * Neither the name of the copyright holder, nor the names of any other
19
19
  # contributors to this software, may be used to endorse or promote products
20
20
  # derived from this software without specific prior written permission.
21
- #
21
+ #
22
22
  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
23
  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
24
  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,16 +38,16 @@ require 'monitor'
38
38
 
39
39
 
40
40
  module Sawmill
41
-
42
-
41
+
42
+
43
43
  # The Sawmill Rotater provides log rotation services for logfile
44
44
  # formatting, supporting several different log rotation strategies.
45
- #
45
+ #
46
46
  # The formatter implemented by Sawmill::EntryProcessor::Format already
47
47
  # recognizes a Rotater as a supported destination, and automatically
48
48
  # interfaces with it to ensure that log records aren't split into
49
49
  # multiple files by rotation.
50
- #
50
+ #
51
51
  # You may also interface with a rotater manually. The core of rotater
52
52
  # usage is the Channel, which lets you ensure that groups of log
53
53
  # entries end up in the same log file regardless of log rotation.
@@ -56,23 +56,23 @@ module Sawmill
56
56
  # where the allowable file breaks are, or by letting the rotater
57
57
  # break the file anywhere it wants. See the create_channel method
58
58
  # and the Channel object for more details.
59
-
59
+
60
60
  class Rotater
61
-
61
+
62
62
  # :stopdoc:
63
63
  SUPPORTS_ENCODING = defined?(::Encoding)
64
64
  ENCODING_OPTS = {:invalid => :replace, :undef => :replace}
65
65
  # :startdoc:
66
-
67
-
66
+
67
+
68
68
  # Create a rotater using the given rotation strategy.
69
69
  # See Sawmill::Rotater::DateBasedLogFile and
70
70
  # Sawmill::Rotater::ShiftingLogFile for examples of common strategies.
71
- #
71
+ #
72
72
  # The rotation strategy can be passed as an object or as a class with a
73
73
  # set of options that will be used to instantiate the strategy.
74
74
  # In addition to those options, the following options are recognized:
75
- #
75
+ #
76
76
  # [<tt>:omit_directives</tt>]
77
77
  # If true, omit standard logfile directives. Default is false.
78
78
  # [<tt>:concurrent_writes</tt>]
@@ -85,7 +85,7 @@ module Sawmill
85
85
  # Specify an encoding for file data. (Ruby 1.9 only).
86
86
  # You may pass either an encoding object or an encoding name.
87
87
  # If not specified, writes raw bytes (e.g. defaults to ASCII-8BIT).
88
-
88
+
89
89
  def initialize(io_manager_, opts_={})
90
90
  @omit_directives = opts_.delete(:omit_directives)
91
91
  @concurrent_writes = opts_.delete(:concurrent_writes)
@@ -103,24 +103,24 @@ module Sawmill
103
103
  @handles ||= {}
104
104
  @mutex ||= ::Monitor.new
105
105
  end
106
-
107
-
106
+
107
+
108
108
  # Create a new Channel for this Rotater. See Sawmill::Rotater::Channel
109
109
  # for details on the Channel object.
110
- #
110
+ #
111
111
  # The following options are recognized:
112
- #
112
+ #
113
113
  # [<tt>:auto_rotate</tt>]
114
114
  # Put the channel in auto-rotate mode. In this mode, the rotater is
115
115
  # allowed to rotate the logfile at any time for that channel. It is
116
116
  # the equivalent of calling check_rotate on the channel after every
117
117
  # write. Default is false.
118
-
118
+
119
119
  def create_channel(opts_={})
120
120
  Channel.new(self, opts_)
121
121
  end
122
-
123
-
122
+
123
+
124
124
  def _write_to_stream(io_, str_) # :nodoc:
125
125
  if SUPPORTS_ENCODING && @encoding
126
126
  str_ = str_.encode(@encoding, ENCODING_OPTS)
@@ -136,8 +136,8 @@ module Sawmill
136
136
  io_.write(str_)
137
137
  end
138
138
  end
139
-
140
-
139
+
140
+
141
141
  def _obtain_handle # :nodoc:
142
142
  handle_ = @io_manager.preferred_handle
143
143
  if @handles.include?(handle_)
@@ -155,8 +155,8 @@ module Sawmill
155
155
  end
156
156
  handle_
157
157
  end
158
-
159
-
158
+
159
+
160
160
  def _release_handle(handle_) # :nodoc:
161
161
  info_ = @handles[handle_]
162
162
  info_[2] -= 1
@@ -166,8 +166,8 @@ module Sawmill
166
166
  end
167
167
  nil
168
168
  end
169
-
170
-
169
+
170
+
171
171
  def _check_rotate_handle(handle_) # :nodoc:
172
172
  if handle_ != @io_manager.preferred_handle
173
173
  _release_handle(handle_)
@@ -176,15 +176,15 @@ module Sawmill
176
176
  handle_
177
177
  end
178
178
  end
179
-
180
-
179
+
180
+
181
181
  def _do_open # :nodoc:
182
182
  @mutex.synchronize do
183
183
  _obtain_handle
184
184
  end
185
185
  end
186
-
187
-
186
+
187
+
188
188
  def _do_write(handle_, str_, auto_rotate_) # :nodoc:
189
189
  @mutex.synchronize do
190
190
  @io_manager.before_write
@@ -196,84 +196,84 @@ module Sawmill
196
196
  handle_
197
197
  end
198
198
  end
199
-
200
-
199
+
200
+
201
201
  def _do_close(handle_) # :nodoc:
202
202
  @mutex.synchronize do
203
203
  _release_handle(handle_)
204
204
  end
205
205
  end
206
-
207
-
206
+
207
+
208
208
  def _do_check_rotate(handle_) # :nodoc:
209
209
  @mutex.synchronize do
210
210
  _check_rotate_handle(handle_)
211
211
  end
212
212
  end
213
-
214
-
213
+
214
+
215
215
  # A channel is a lightweight object that responds to the write and close
216
216
  # methods; that is, it is sufficient for Sawmill::Formatter.
217
- #
217
+ #
218
218
  # When a channel is opened, it locks down a path to the logfile and
219
219
  # ensures that the logfile will not rotate out from under it; that is,
220
220
  # writes to a channel are ensured to end up in the same physical file.
221
- #
221
+ #
222
222
  # You may choose, at intervals, to explicitly tell the channel that it
223
223
  # is okay to rotate the logfile now, by calling check_rotate.
224
- #
224
+ #
225
225
  # You must close a channel when you are done with it. Closing a channel
226
226
  # does not close the underlying logfile, but instead tells the rotater
227
227
  # that you are done with this channel and that the logfile is free to
228
228
  # rotate independent of it.
229
- #
229
+ #
230
230
  # You may have any number of channels open at any time, each on a
231
231
  # different rotation schedule. Each may possibly be writing to different
232
232
  # files in the rotation at any time, but this is all done automatically
233
233
  # behind the scenes.
234
-
234
+
235
235
  class Channel
236
-
236
+
237
237
  def initialize(rotater_, opts_={}) # :nodoc:
238
238
  @rotater = rotater_
239
239
  @auto_rotate = opts_[:auto_rotate]
240
240
  @io_handle = @rotater._do_open
241
241
  end
242
-
243
-
242
+
243
+
244
244
  # Write a string to this channel.
245
-
245
+
246
246
  def write(str_)
247
247
  if @io_handle
248
248
  @rotater._do_write(@io_handle, str_, @auto_rotate)
249
249
  end
250
250
  end
251
-
252
-
251
+
252
+
253
253
  # Close this channel, telling the rotater that this channel no longer
254
254
  # needs to constrain the log rotation.
255
-
255
+
256
256
  def close
257
257
  if @io_handle
258
258
  @rotater._do_close(@io_handle)
259
259
  @io_handle = nil
260
260
  end
261
261
  end
262
-
263
-
262
+
263
+
264
264
  # Manually tell the rotater that this channel is at a stopping point
265
265
  # and that the log file may rotate at this time.
266
-
266
+
267
267
  def check_rotate
268
268
  if @io_handle
269
269
  @io_handle = @rotater._do_check_rotate(@io_handle)
270
270
  end
271
271
  end
272
-
273
-
272
+
273
+
274
274
  end
275
-
276
-
275
+
276
+
277
277
  end
278
-
278
+
279
279
  end