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 entry 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,50 +35,50 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # This processor reports the number of records processed.
43
-
43
+
44
44
  class CountRecords < Base
45
-
46
-
45
+
46
+
47
47
  # Create a count-records report.
48
- #
48
+ #
49
49
  # Recognized options include:
50
- #
50
+ #
51
51
  # [<tt>:label</tt>]
52
52
  # Label to use for the report.
53
53
  # If provided, the report is returned as a string of the form
54
54
  # "#{label}#{value}"
55
55
  # If set to nil or absent, the report is returned as an integer.
56
-
56
+
57
57
  def initialize(opts_={})
58
58
  @label = opts_[:label]
59
59
  @finished = false
60
60
  @count = 0
61
61
  end
62
-
63
-
62
+
63
+
64
64
  def record(record_)
65
65
  @count += 1 unless @finished
66
66
  true
67
67
  end
68
-
68
+
69
69
  def extra_entry(entry_)
70
70
  true
71
71
  end
72
-
72
+
73
73
  def finish
74
74
  @finished = true
75
75
  @label ? "#{@label}#{@count}" : @count
76
76
  end
77
-
78
-
77
+
78
+
79
79
  end
80
-
81
-
80
+
81
+
82
82
  end
83
-
83
+
84
84
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor that decomposes a record into entries
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,41 +35,41 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # A processor that decomposes records into constituent entries and
43
43
  # passes those entries to an entry processor.
44
-
44
+
45
45
  class Decompose < Base
46
-
47
-
46
+
47
+
48
48
  # Create a new decomposer that emits to the given entry processor.
49
-
49
+
50
50
  def initialize(processor_, opts_={})
51
51
  @processor = processor_
52
52
  @classifier = EntryClassifier.new(processor_)
53
53
  end
54
-
55
-
54
+
55
+
56
56
  def record(record_)
57
57
  record_.each_entry{ |entry_| @classifier.entry(entry_) }
58
58
  true
59
59
  end
60
-
60
+
61
61
  def extra_entry(entry_)
62
62
  @classifier.entry(entry_)
63
63
  true
64
64
  end
65
-
65
+
66
66
  def finish
67
67
  @processor.finish
68
68
  end
69
-
69
+
70
70
  end
71
-
72
-
71
+
72
+
73
73
  end
74
-
74
+
75
75
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor that checks record attribute values
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,28 +35,28 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # A record filter that checks attribute values.
43
- #
43
+ #
44
44
  # This is a boolean processor, so it merely returns true or false based
45
45
  # on the filter result. Use this in conjunction with an If processor to
46
46
  # actually perform other actions based on the result.
47
-
47
+
48
48
  class FilterByAttributes < Base
49
-
50
-
49
+
50
+
51
51
  # Create a new filter. Pass the attribute names and values to check
52
52
  # as a hash.
53
-
53
+
54
54
  def initialize(attributes_)
55
55
  @attributes = {}
56
56
  attributes_.each{ |key_, value_| @attributes[key_.to_s] = value_ }
57
57
  end
58
-
59
-
58
+
59
+
60
60
  def record(record_)
61
61
  @attributes.each do |key_, value_|
62
62
  record_value_ = record_.attribute(key_.to_s)
@@ -71,18 +71,18 @@ module Sawmill
71
71
  end
72
72
  true
73
73
  end
74
-
74
+
75
75
  def extra_entry(entry_)
76
76
  false
77
77
  end
78
-
78
+
79
79
  def finish
80
80
  nil
81
81
  end
82
-
82
+
83
83
  end
84
-
85
-
84
+
85
+
86
86
  end
87
-
87
+
88
88
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor that calls a block
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,61 +35,61 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # A record filter that calls a block to perform its check.
43
- #
43
+ #
44
44
  # This is a boolean processor, so it merely returns true or false based
45
45
  # on the filter result. Use this in conjunction with an If processor to
46
46
  # actually perform other actions based on the result.
47
-
47
+
48
48
  class FilterByBlock < Base
49
-
50
-
49
+
50
+
51
51
  # Create a new filter. Provide the block, which should take a
52
52
  # Sawmill::Record as the parameter and return a boolean.
53
- #
53
+ #
54
54
  # By default, extra entries always return false. Provide an
55
55
  # extra entry filter to change this behavior.
56
-
56
+
57
57
  def initialize(&block_)
58
58
  to_filter_record(&block_)
59
59
  end
60
-
61
-
60
+
61
+
62
62
  # Provide a block to filter records. It should take a Sawmill::Record
63
63
  # as the parameter, and return a boolean.
64
-
64
+
65
65
  def to_filter_record(&block_)
66
66
  @block = block_ || Proc.new{ |record_| false }
67
67
  end
68
-
69
-
68
+
69
+
70
70
  # Provide a block to filter extra entries. It should take an entry
71
71
  # object as the parameter, and return a boolean.
72
-
72
+
73
73
  def to_filter_extra_entry(&block_)
74
74
  @extra_entry_block = block_ || Proc.new{ |entry_| false }
75
75
  end
76
-
77
-
76
+
77
+
78
78
  def record(record_)
79
79
  @block.call(record_)
80
80
  end
81
-
81
+
82
82
  def extra_entry(entry_)
83
83
  @extra_entry_block.call(entry_)
84
84
  end
85
-
85
+
86
86
  def finish
87
87
  nil
88
88
  end
89
-
89
+
90
90
  end
91
-
92
-
91
+
92
+
93
93
  end
94
-
94
+
95
95
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill record processor that checks record IDs
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,44 +35,44 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module RecordProcessor
40
-
41
-
40
+
41
+
42
42
  # A record filter that checks record IDs.
43
- #
43
+ #
44
44
  # This is a boolean processor, so it merely returns true or false based
45
45
  # on the filter result. Use this in conjunction with an If processor to
46
46
  # actually perform other actions based on the result.
47
-
47
+
48
48
  class FilterByRecordID < Base
49
-
50
-
49
+
50
+
51
51
  # Create a new filter that checks against the given record ID.
52
52
  # The given ID may be a string or a Regexp, in which case the filter
53
53
  # will check for equality or regular expression match, respectively.
54
-
54
+
55
55
  def initialize(id_)
56
56
  @record_id = id_
57
57
  end
58
-
59
-
58
+
59
+
60
60
  def record(record_)
61
61
  @record_id === record_.record_id
62
62
  end
63
-
63
+
64
64
  def extra_entry(entry_)
65
65
  id_ = entry_.respond_to?(:record_id) ? entry_.record_id : nil
66
66
  @record_id === id_
67
67
  end
68
-
68
+
69
69
  def finish
70
70
  nil
71
71
  end
72
-
72
+
73
73
  end
74
-
75
-
74
+
75
+
76
76
  end
77
-
77
+
78
78
  end