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,19 +35,19 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module EntryProcessor
40
-
41
-
40
+
41
+
42
42
  # This processor reports the number of entries processed.
43
-
43
+
44
44
  class CountEntries < Base
45
-
46
-
45
+
46
+
47
47
  # Create a count-entries 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
@@ -62,7 +62,7 @@ module Sawmill
62
62
  # [<tt>:omit_record_delimiters</tt>]
63
63
  # If set to true, omits begin_record and end_record from the count.
64
64
  # Default is false.
65
-
65
+
66
66
  def initialize(opts_={})
67
67
  @label = opts_[:label]
68
68
  @omit_unknown_data = opts_[:omit_unknown_data]
@@ -71,42 +71,42 @@ module Sawmill
71
71
  @finished = false
72
72
  @count = 0
73
73
  end
74
-
75
-
74
+
75
+
76
76
  def begin_record(entry_)
77
77
  @count += 1 unless @finished || @omit_record_delimiters
78
78
  true
79
79
  end
80
-
80
+
81
81
  def end_record(entry_)
82
82
  @count += 1 unless @finished || @omit_record_delimiters
83
83
  true
84
84
  end
85
-
85
+
86
86
  def message(entry_)
87
87
  @count += 1 unless @finished
88
88
  true
89
89
  end
90
-
90
+
91
91
  def attribute(entry_)
92
92
  @count += 1 unless @finished || @omit_attributes
93
93
  true
94
94
  end
95
-
95
+
96
96
  def unknown_data(entry_)
97
97
  @count += 1 unless @finished || @omit_unknown_data
98
98
  true
99
99
  end
100
-
100
+
101
101
  def finish
102
102
  @finished = true
103
103
  @label ? "#{@label}#{@count}" : @count
104
104
  end
105
-
106
-
105
+
106
+
107
107
  end
108
-
109
-
108
+
109
+
110
110
  end
111
-
111
+
112
112
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill entry processor that checks for entry field 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,23 +35,23 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module EntryProcessor
40
-
41
-
40
+
41
+
42
42
  # A basic filter that knows how to check level and progname.
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 FilterByBasicFields < Base
49
-
50
-
49
+
50
+
51
51
  # Create a new filter.
52
- #
52
+ #
53
53
  # Recognized options include:
54
- #
54
+ #
55
55
  # [<tt>:level</tt>]
56
56
  # Lowest level that will be accepted. This should be either a
57
57
  # Sawmill::Level object or an integer value or string/symbol that
@@ -77,7 +77,7 @@ module Sawmill
77
77
  # [<tt>:accept_unknown</tt>]
78
78
  # If set to true, accepts all entries of type :unknown_data.
79
79
  # Otherwise, rejects all such entries.
80
-
80
+
81
81
  def initialize(opts_={})
82
82
  @level = opts_[:level]
83
83
  @progname = opts_[:progname]
@@ -86,36 +86,36 @@ module Sawmill
86
86
  @accept_incomparable_levels = opts_[:accept_incomparable_levels]
87
87
  @accept_unknown = opts_[:accept_unknown]
88
88
  end
89
-
90
-
89
+
90
+
91
91
  def begin_record(entry_)
92
92
  @accept_record_delimiters.nil? ? _check_filter(entry_) : @accept_record_delimiters
93
93
  end
94
-
94
+
95
95
  def end_record(entry_)
96
96
  @accept_record_delimiters.nil? ? _check_filter(entry_) : @accept_record_delimiters
97
97
  end
98
-
98
+
99
99
  def message(entry_)
100
100
  _check_filter(entry_)
101
101
  end
102
-
102
+
103
103
  def attribute(entry_)
104
104
  @accept_attributes.nil? ? _check_filter(entry_) : @accept_attributes
105
105
  end
106
-
106
+
107
107
  def unknown_data(entry_)
108
108
  @accept_unknown
109
109
  end
110
-
110
+
111
111
  def finish
112
112
  nil
113
113
  end
114
-
115
-
114
+
115
+
116
116
  private
117
-
118
-
117
+
118
+
119
119
  def _check_filter(entry_) # :nodoc:
120
120
  if @level
121
121
  level_ = entry_.level
@@ -135,11 +135,11 @@ module Sawmill
135
135
  return false if @progname && entry_.progname != @progname
136
136
  true
137
137
  end
138
-
139
-
138
+
139
+
140
140
  end
141
-
142
-
141
+
142
+
143
143
  end
144
-
144
+
145
145
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill entry 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,62 +35,62 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module EntryProcessor
40
-
41
-
40
+
41
+
42
42
  # A entry 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 an entry
52
52
  # object as the parameter and return a boolean.
53
-
53
+
54
54
  def initialize(&block_)
55
55
  to_filter_entry(&block_)
56
56
  end
57
-
58
-
57
+
58
+
59
59
  # Provide a block to filter entries. It should take an entry object
60
60
  # as the parameter, and return a boolean.
61
-
61
+
62
62
  def to_filter_entry(&block_)
63
63
  @block = block_ || Proc.new{ |entry_| false }
64
64
  end
65
-
66
-
65
+
66
+
67
67
  def begin_record(entry_)
68
68
  @block.call(entry_)
69
69
  end
70
-
70
+
71
71
  def end_record(entry_)
72
72
  @block.call(entry_)
73
73
  end
74
-
74
+
75
75
  def message(entry_)
76
76
  @block.call(entry_)
77
77
  end
78
-
78
+
79
79
  def attribute(entry_)
80
80
  @block.call(entry_)
81
81
  end
82
-
82
+
83
83
  def unknown_data(entry_)
84
84
  @block.call(entry_)
85
85
  end
86
-
86
+
87
87
  def finish
88
88
  nil
89
89
  end
90
-
90
+
91
91
  end
92
-
93
-
92
+
93
+
94
94
  end
95
-
95
+
96
96
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill entry 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 EntryProcessor
40
-
41
-
40
+
41
+
42
42
  # This processor formats log entries 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>]
@@ -68,16 +68,19 @@ module Sawmill
68
68
  # [<tt>:length_limit</tt>]
69
69
  # Limit to the entry length. Entries are truncated to this length
70
70
  # when written. If not specified, entries are not truncated.
71
-
71
+
72
72
  def initialize(destination_, opts_={})
73
73
  if destination_.kind_of?(Rotater)
74
74
  @rotater = destination_
75
75
  @channels = {}
76
76
  @standby_channel = nil
77
- elsif destination_.respond_to?(:close) && destination_.respond_to?(:write)
78
- @io = destination_
79
77
  else
80
- raise ::ArgumentError, "Unknown destination type"
78
+ @rotater = nil
79
+ if destination_.respond_to?(:close) && destination_.respond_to?(:write)
80
+ @io = destination_
81
+ else
82
+ raise ::ArgumentError, "Unknown destination type"
83
+ end
81
84
  end
82
85
  @include_id = opts_[:include_id]
83
86
  @fractional_second_digits = (opts_[:fractional_second_digits] || 2).to_i
@@ -87,9 +90,11 @@ module Sawmill
87
90
  (6 - @fractional_second_digits).times{ @usec_factor *= 10 }
88
91
  @level_width = opts_[:level_width]
89
92
  @length_limit = opts_[:length_limit]
93
+ @local_time = opts_[:local_time]
94
+ @iso_8601_time = opts_[:iso_8601_time]
90
95
  end
91
-
92
-
96
+
97
+
93
98
  def begin_record(entry_)
94
99
  return false unless @io || @rotater
95
100
  record_id_ = entry_.record_id
@@ -108,7 +113,7 @@ module Sawmill
108
113
  io_.write(_format_entry(entry_, '^', "BEGIN #{record_id_}"))
109
114
  true
110
115
  end
111
-
116
+
112
117
  def end_record(entry_)
113
118
  return false unless @io || @rotater
114
119
  record_id_ = entry_.record_id
@@ -127,13 +132,13 @@ module Sawmill
127
132
  end
128
133
  true
129
134
  end
130
-
135
+
131
136
  def message(entry_)
132
137
  return false unless @io || @rotater
133
138
  _write_str(_format_entry(entry_, '.', entry_.message), entry_.record_id)
134
139
  true
135
140
  end
136
-
141
+
137
142
  def attribute(entry_)
138
143
  return false unless @io || @rotater
139
144
  opcode_ = entry_.operation == :append ? '+' : '='
@@ -141,13 +146,13 @@ module Sawmill
141
146
  _write_str(str_, entry_.record_id)
142
147
  true
143
148
  end
144
-
149
+
145
150
  def unknown_data(entry_)
146
151
  return false unless @io || @rotater
147
152
  _write_str(entry_.line+"\n", nil)
148
153
  true
149
154
  end
150
-
155
+
151
156
  def finish
152
157
  if @rotater
153
158
  @default_channel.close
@@ -159,9 +164,9 @@ module Sawmill
159
164
  end
160
165
  nil
161
166
  end
162
-
167
+
163
168
  private
164
-
169
+
165
170
  def _write_str(str_, record_id_) # :nodoc:
166
171
  if @rotater
167
172
  io_ = @channels[record_id_]
@@ -176,7 +181,7 @@ module Sawmill
176
181
  @io.write(str_)
177
182
  end
178
183
  end
179
-
184
+
180
185
  def _format_entry(entry_, marker_, str_) # :nodoc:
181
186
  id_ = @include_id ? entry_.record_id : nil
182
187
  id_ = id_ ? ' '+id_ : ''
@@ -222,16 +227,16 @@ module Sawmill
222
227
  end
223
228
  "[#{levelstr_} #{timestr_} #{entry_.progname}#{id_} #{marker_}] #{str_}\n"
224
229
  end
225
-
230
+
226
231
  end
227
-
228
-
232
+
233
+
229
234
  end
230
-
231
-
235
+
236
+
232
237
  # Sawmill::Formatter is an alternate name for
233
238
  # Sawmill::EntryProcessor::Format
234
239
  Formatter = EntryProcessor::Format
235
-
236
-
240
+
241
+
237
242
  end