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 interface
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,62 +35,62 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
39
-
38
+
39
+
40
40
  # Entry processors are objects that receive a stream of log records and
41
41
  # perform some action. Some processors perform their own action, while
42
42
  # others could filter records and forward them to other processors.
43
- #
43
+ #
44
44
  # The API contract for a record processor is specified by the class
45
45
  # Sawmill::RecordProcessor::Base. Processors could subclass that base
46
46
  # class, or could just duck-type the methods.
47
- #
47
+ #
48
48
  # Sawmill's basic record processor classes live into this module's
49
49
  # namespace, but this is not a requirement for your own processors.
50
-
50
+
51
51
  module RecordProcessor
52
-
53
-
52
+
53
+
54
54
  class Builder # :nodoc:
55
55
  include ::Blockenspiel::DSL
56
56
  end
57
-
58
-
57
+
58
+
59
59
  # A base class for record processors.
60
- #
60
+ #
61
61
  # Record processors need not necessarily subclass this class, but should
62
62
  # at least duck-type the methods.
63
- #
63
+ #
64
64
  # If a class subclasses this class, *and* lives in the RecordProcessor
65
65
  # namespace, then it will automatically be available in the build
66
66
  # interface. See RecordProcessor#build.
67
-
67
+
68
68
  class Base
69
-
70
-
69
+
70
+
71
71
  # Receive and process a Sawmill::Record.
72
-
72
+
73
73
  def record(record_)
74
74
  true
75
75
  end
76
-
77
-
76
+
77
+
78
78
  # Receive and process an entry that falls outside a record.
79
-
79
+
80
80
  def extra_entry(entry_)
81
81
  true
82
82
  end
83
-
84
-
83
+
84
+
85
85
  # Close down the processor, perform any finishing tasks, and return
86
86
  # any final calculated value.
87
- #
87
+ #
88
88
  # After this is called, the processor should ignore any further entries.
89
- #
89
+ #
90
90
  # The return value can be used to communicate a final computed value,
91
91
  # analysis report, or other data back to the caller. It may also be
92
92
  # nil, signalling no finish value.
93
- #
93
+ #
94
94
  # Note that some processors function to multiplex other processors. In
95
95
  # such a case, their finish value needs to be an aggregate of the
96
96
  # values returned by their descendants. To handle these cases, we
@@ -103,12 +103,12 @@ module Sawmill
103
103
  # actually return an array _as_ a value, you must wrap it in another
104
104
  # array, indicating "an array of one finish value, and that finish
105
105
  # value also happens to be an array itself".
106
-
106
+
107
107
  def finish
108
108
  nil
109
109
  end
110
-
111
-
110
+
111
+
112
112
  def self.inherited(subclass_) # :nodoc:
113
113
  if subclass_.name =~ /^Sawmill::RecordProcessor::([^:]+)$/
114
114
  name_ = $1
@@ -119,23 +119,23 @@ module Sawmill
119
119
  end
120
120
  end
121
121
  end
122
-
123
-
122
+
123
+
124
124
  # Add a method to the processor building DSL. You may call this method
125
125
  # in the DSL to create an instance of this record processor.
126
126
  # You must pass a method name that begins with a lower-case letter or
127
127
  # underscore.
128
- #
128
+ #
129
129
  # Processors that subclass Sawmill::RecordProcessor::Base and live in
130
130
  # the Sawmill::RecordProcessor namespace will have their class name
131
131
  # automatically added to the DSL. This method is primarily for other
132
132
  # processors that do not live in that module namespace.
133
- #
133
+ #
134
134
  # See Sawmill::RecordProcessor#build for more information.
135
- #
135
+ #
136
136
  # Raises Sawmill::Errors::DSLMethodError if the given name is already
137
137
  # taken.
138
-
138
+
139
139
  def self.add_dsl_method(name_)
140
140
  klass_ = self
141
141
  if name_.to_s !~ /^[a-z_]/
@@ -150,14 +150,14 @@ module Sawmill
150
150
  end
151
151
  end
152
152
  end
153
-
154
-
153
+
154
+
155
155
  private
156
-
156
+
157
157
  def _interpret_processor_array(param_) # :nodoc:
158
158
  param_.flatten.map{ |processor_| _interpret_processor(processor_) }
159
159
  end
160
-
160
+
161
161
  def _interpret_processor(param_) # :nodoc:
162
162
  case param_
163
163
  when ::Class
@@ -168,34 +168,34 @@ module Sawmill
168
168
  raise ::ArgumentError, "Unknown processor object of type #{param_.class.name}"
169
169
  end
170
170
  end
171
-
172
-
171
+
172
+
173
173
  end
174
-
175
-
174
+
175
+
176
176
  # A convenience DSL for building sets of processors. This is typically
177
177
  # useful for constructing if-expressions using the boolean operation
178
178
  # processors.
179
- #
179
+ #
180
180
  # Every record processor that lives in the Sawmill::RecordProcessor
181
181
  # module and subclasses Sawmill::RecordProcessor::Base can be
182
182
  # instantiated by using its name as a function call. Other processors
183
183
  # may also add themselves to the DSL by calling
184
184
  # Sawmill::RecordProcessor::Base#add_dsl_method.
185
- #
185
+ #
186
186
  # For example:
187
- #
187
+ #
188
188
  # Sawmill::RecordProcessor.build do
189
189
  # If(Or(FilterByRecordId('12345678'), FilterByRecordId('abcdefg')),
190
190
  # Format(STDOUT))
191
191
  # end
192
-
192
+
193
193
  def self.build(&block_)
194
194
  ::Blockenspiel.invoke(block_, Builder.new)
195
195
  end
196
-
197
-
196
+
197
+
198
198
  end
199
-
200
-
199
+
200
+
201
201
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor that generates reports
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 collects and formats reports from descendant
44
44
  # record processors.
45
-
45
+
46
46
  class CompileReport < All
47
-
48
-
47
+
48
+
49
49
  # Create a report collection.
50
- #
50
+ #
51
51
  # Recognized options include:
52
- #
52
+ #
53
53
  # [<tt>:postprocessor</tt>]
54
54
  # Postprocessor proc for individual reports.
55
55
  # [<tt>:separator</tt>]
@@ -60,7 +60,7 @@ module Sawmill
60
60
  # [<tt>:footer</tt>]
61
61
  # Footer string for the final compiled report.
62
62
  # Default is the empty string.
63
-
63
+
64
64
  def initialize(*children_)
65
65
  opts_ = children_.last.kind_of?(::Hash) ? children_.pop : {}
66
66
  @postprocessor = opts_[:postprocessor]
@@ -69,32 +69,32 @@ module Sawmill
69
69
  @footer = opts_[:footer] || ''
70
70
  super(*children_)
71
71
  end
72
-
73
-
72
+
73
+
74
74
  # Separator string to be inserted between individual reports.
75
75
  attr_accessor :separator
76
-
76
+
77
77
  # Header string for the final compiled report.
78
78
  attr_accessor :header
79
-
79
+
80
80
  # Footer string for the final compiled report.
81
81
  attr_accessor :footer
82
-
83
-
82
+
83
+
84
84
  # Provide a postprocessor block for individual report values.
85
85
  # This block should take a single parameter and return a string
86
86
  # that should be included in the compiled report. It may also
87
87
  # return nil to indicate that the data should not be included.
88
-
88
+
89
89
  def to_postprocess_value(&block_)
90
90
  @postprocessor = block_
91
91
  end
92
-
93
-
92
+
93
+
94
94
  # On finish, this processor calls finish on its descendants, converts
95
95
  # their values into strings and compiles them into a report. It then
96
96
  # returns that report as a string.
97
-
97
+
98
98
  def finish
99
99
  values_ = super || []
100
100
  values_ = [values_] unless values_.kind_of?(::Array)
@@ -102,12 +102,12 @@ module Sawmill
102
102
  values_.compact!
103
103
  "#{@header}#{values_.join(@separator)}#{@footer}"
104
104
  end
105
-
106
-
105
+
106
+
107
107
  end
108
-
109
-
108
+
109
+
110
110
  end
111
-
112
-
111
+
112
+
113
113
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill basic entry processors that implement conditionals
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,39 +35,39 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # An "if" conditional.
43
- #
43
+ #
44
44
  # Takes a boolean condition processor and executes a processor on true
45
45
  # (and optionally another one on false).
46
- #
46
+ #
47
47
  # For example, this builds a processor that sends formatted log records
48
48
  # to STDOUT only if they have a "user" attribute of "daniel":
49
- #
49
+ #
50
50
  # processor = Sawmill::RecordProcessor.build do
51
51
  # If(FilterByAttributes('user' => 'daniel'), Format(STDOUT))
52
52
  # end
53
-
53
+
54
54
  class If < Base
55
-
56
-
55
+
56
+
57
57
  # Create an "if" conditional.
58
- #
58
+ #
59
59
  # The first parameter must be a processor whose methods return a
60
60
  # boolean value indicating whether the record should be accepted.
61
61
  # The second parameter is a processor to run on accepted records.
62
62
  # The optional third parameter is an "else" processor to run on
63
63
  # rejected records.
64
-
64
+
65
65
  def initialize(condition_, on_true_, on_false_=nil)
66
66
  @condition = condition_
67
67
  @on_true = on_true_
68
68
  @on_false = on_false_
69
69
  end
70
-
70
+
71
71
  def record(record_)
72
72
  if @condition.record(record_)
73
73
  @on_true.record(record_)
@@ -75,7 +75,7 @@ module Sawmill
75
75
  @on_false.record(record_)
76
76
  end
77
77
  end
78
-
78
+
79
79
  def extra_entry(entry_)
80
80
  if @condition.extra_entry(entry_)
81
81
  @on_true.extra_entry(entry_)
@@ -83,247 +83,247 @@ module Sawmill
83
83
  @on_false.extra_entry(entry_)
84
84
  end
85
85
  end
86
-
86
+
87
87
  def finish
88
88
  Util::ProcessorTools.collect_finish_values([@on_true, @on_false])
89
89
  end
90
-
91
-
90
+
91
+
92
92
  end
93
-
94
-
93
+
94
+
95
95
  # A boolean processor that returns the boolean negation of a given
96
96
  # processor.
97
- #
97
+ #
98
98
  # For example, this builds a processor that sends formatted log records
99
99
  # to STDOUT only if they do NOT have a "user" attribute of "daniel":
100
- #
100
+ #
101
101
  # processor = Sawmill::RecordProcessor.build do
102
102
  # If(Not(FilterByAttributes('user' => 'daniel')), Format(STDOUT))
103
103
  # end
104
-
104
+
105
105
  class Not < Base
106
-
107
-
106
+
107
+
108
108
  # Create a "not" boolean.
109
109
  # The parameter is a boolean processor to run. This processor returns
110
110
  # the boolean negation of its output.
111
-
111
+
112
112
  def initialize(child_)
113
113
  @child = _interpret_processor(child_)
114
114
  end
115
-
115
+
116
116
  def record(record_)
117
117
  !@child.record(record_)
118
118
  end
119
-
119
+
120
120
  def extra_entry(entry_)
121
121
  !@child.extra_entry(record_)
122
122
  end
123
-
123
+
124
124
  def finish
125
125
  @child.finish
126
126
  end
127
-
128
-
127
+
128
+
129
129
  end
130
-
131
-
130
+
131
+
132
132
  # A boolean processor that returns true if and only if all its child
133
133
  # processors return true. This version short-circuits the processing,
134
134
  # so once one child returns false, subsequent children are not called
135
135
  # at all.
136
- #
136
+ #
137
137
  # For example, this builds a processor that sends formatted log records
138
138
  # to STDOUT only if they have a "user" attribute of "daniel" AND their
139
139
  # record ID is '12345678':
140
- #
140
+ #
141
141
  # processor = Sawmill::RecordProcessor.build do
142
142
  # If(And(FilterByAttributes('user' => 'daniel'),
143
143
  # FilterByRecordID('12345678')),
144
144
  # Format(STDOUT))
145
145
  # end
146
-
146
+
147
147
  class And < Base
148
-
149
-
148
+
149
+
150
150
  # Create an "and" boolean.
151
151
  # The parameters are child processors whose return values should be
152
152
  # combined with an AND operation.
153
-
153
+
154
154
  def initialize(*children_)
155
155
  @children = _interpret_processor_array(children_)
156
156
  end
157
-
157
+
158
158
  def record(record_)
159
159
  @children.each do |child_|
160
160
  return false unless child_.record(record_)
161
161
  end
162
162
  true
163
163
  end
164
-
164
+
165
165
  def extra_entry(entry_)
166
166
  @children.each do |child_|
167
167
  return false unless child_.extra_entry(entry_)
168
168
  end
169
169
  true
170
170
  end
171
-
171
+
172
172
  def finish
173
173
  Util::ProcessorTools.collect_finish_values(@children)
174
174
  end
175
-
176
-
175
+
176
+
177
177
  end
178
-
179
-
178
+
179
+
180
180
  # A boolean processor that returns true if and only if any of its child
181
181
  # processors returns true. This version short-circuits the processing,
182
182
  # so once one child returns true, subsequent children are not called
183
183
  # at all.
184
- #
184
+ #
185
185
  # For example, this builds a processor that sends formatted log records
186
186
  # to STDOUT only if they have a "user" attribute of "daniel" OR their
187
187
  # record ID is '12345678':
188
- #
188
+ #
189
189
  # processor = Sawmill::RecordProcessor.build do
190
190
  # If(Or(FilterByAttributes('user' => 'daniel'),
191
191
  # FilterByRecordID('12345678')),
192
192
  # Format(STDOUT))
193
193
  # end
194
-
194
+
195
195
  class Or < Base
196
-
197
-
196
+
197
+
198
198
  # Create an "or" boolean.
199
199
  # The parameters are child processors whose return values should be
200
200
  # combined with an OR operation.
201
-
201
+
202
202
  def initialize(*children_)
203
203
  @children = _interpret_processor_array(children_)
204
204
  end
205
-
205
+
206
206
  def record(record_)
207
207
  @children.each do |child_|
208
208
  return true if child_.record(record_)
209
209
  end
210
210
  false
211
211
  end
212
-
212
+
213
213
  def extra_entry(entry_)
214
214
  @children.each do |child_|
215
215
  return true if child_.extra_entry(entry_)
216
216
  end
217
217
  false
218
218
  end
219
-
219
+
220
220
  def finish
221
221
  Util::ProcessorTools.collect_finish_values(@children)
222
222
  end
223
-
224
-
223
+
224
+
225
225
  end
226
-
227
-
226
+
227
+
228
228
  # A boolean processor that returns true if and only if all its child
229
229
  # processors return true. This version does not short-circuit the
230
230
  # processing, so all children are always called even if an early one
231
231
  # returns false. Thus, this processor is also a good one to use as a
232
232
  # multiplexor to simply run a bunch of processors.
233
- #
233
+ #
234
234
  # For example, this builds a processor that sends formatted log records
235
235
  # to STDOUT only if they have a "user" attribute of "daniel" AND their
236
236
  # record ID is '12345678':
237
- #
237
+ #
238
238
  # processor = Sawmill::RecordProcessor.build do
239
239
  # If(All(FilterByAttributes('user' => 'daniel'),
240
240
  # FilterByRecordID('12345678')),
241
241
  # Format(STDOUT))
242
242
  # end
243
- #
243
+ #
244
244
  # This processor just formats both to STDOUT and STDERR:
245
- #
245
+ #
246
246
  # processor = Sawmill::RecordProcessor.build do
247
247
  # All(Format(STDOUT), Format(STDERR))
248
248
  # end
249
-
249
+
250
250
  class All < Base
251
-
252
-
251
+
252
+
253
253
  # Create an "all" boolean.
254
254
  # The parameters are child processors whose return values should be
255
255
  # combined with an AND operation.
256
-
256
+
257
257
  def initialize(*children_)
258
258
  @children = _interpret_processor_array(children_)
259
259
  end
260
-
260
+
261
261
  def record(record_)
262
262
  @children.inject(true) do |result_, child_|
263
263
  child_.record(record_) && result_
264
264
  end
265
265
  end
266
-
266
+
267
267
  def extra_entry(entry_)
268
268
  @children.inject(true) do |result_, child_|
269
269
  child_.extra_entry(entry_) && result_
270
270
  end
271
271
  end
272
-
272
+
273
273
  def finish
274
274
  Util::ProcessorTools.collect_finish_values(@children)
275
275
  end
276
-
277
-
276
+
277
+
278
278
  end
279
-
280
-
279
+
280
+
281
281
  # A boolean processor that returns true if and only if any of its child
282
282
  # processors returns true. This version does not short-circuit the
283
283
  # processing, so all children are always called even if an early one
284
284
  # returns true.
285
- #
285
+ #
286
286
  # For example, this builds a processor that sends formatted log records
287
287
  # to STDOUT only if they have a "user" attribute of "daniel" OR their
288
288
  # record ID is '12345678':
289
- #
289
+ #
290
290
  # processor = Sawmill::RecordProcessor.build do
291
291
  # If(Any(FilterByAttributes('user' => 'daniel'),
292
292
  # FilterByRecordID('12345678')),
293
293
  # Format(STDOUT))
294
294
  # end
295
-
295
+
296
296
  class Any < Base
297
-
298
-
297
+
298
+
299
299
  # Create an "any" boolean.
300
300
  # The parameters are child processors whose return values should be
301
301
  # combined with an OR operation.
302
-
302
+
303
303
  def initialize(*children_)
304
304
  @children = _interpret_processor_array(children_)
305
305
  end
306
-
306
+
307
307
  def record(record_)
308
308
  @children.inject(false) do |result_, child_|
309
309
  child_.record(record_) || result_
310
310
  end
311
311
  end
312
-
312
+
313
313
  def extra_entry(entry_)
314
314
  @children.inject(false) do |result_, child_|
315
315
  child_.extra_entry(entry_) || result_
316
316
  end
317
317
  end
318
-
318
+
319
319
  def finish
320
320
  Util::ProcessorTools.collect_finish_values(@children)
321
321
  end
322
-
323
-
322
+
323
+
324
324
  end
325
-
326
-
325
+
326
+
327
327
  end
328
-
328
+
329
329
  end