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 stats middleware class
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
  # A Rack middleware that writes a stats log.
41
41
  # Insert this in your Rack stack to generate a stats log.
42
-
42
+
43
43
  class StatsMiddleware
44
-
45
-
44
+
45
+
46
46
  # Create a middleware object for Rack.
47
- #
47
+ #
48
48
  # If you do not provide a logger object, one will be generated for you
49
49
  # that simply logs to STDOUT.
50
- #
50
+ #
51
51
  # Recognized options include:
52
- #
52
+ #
53
53
  # [<tt>:level</tt>]
54
54
  # The level to log at. Default is <tt>:ANY</tt>.
55
55
  # [<tt>:stats_data_key</tt>]
@@ -81,7 +81,7 @@ module Sawmill
81
81
  # logger and the rack environment. Optional.
82
82
  # If a proc is provided and returns false, then stats logging is
83
83
  # canceled for this request.
84
-
84
+
85
85
  def initialize(app_, logger_=nil, level_=nil, opts_={})
86
86
  @app = app_
87
87
  @logger = logger_ || Logger.new(:progname => 'stats', :processor => Formatter.new(::STDOUT))
@@ -95,8 +95,8 @@ module Sawmill
95
95
  @pre_logger = opts_[:pre_logger]
96
96
  @post_logger = opts_[:post_logger]
97
97
  end
98
-
99
-
98
+
99
+
100
100
  def call(env_)
101
101
  env_[@stats_data_key] = stats_data_ = {}
102
102
  start_time_ = ::Time.now.utc
@@ -130,9 +130,9 @@ module Sawmill
130
130
  end
131
131
  end
132
132
  end
133
-
134
-
133
+
134
+
135
135
  end
136
-
137
-
136
+
137
+
138
138
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill railtie
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
@@ -39,28 +39,28 @@ require 'rails/railtie'
39
39
 
40
40
 
41
41
  module Sawmill
42
-
43
-
42
+
43
+
44
44
  # Railtie that sets up a stats logger. Installs a
45
45
  # Sawmill::StatsMiddleware to enable a stats log.
46
- #
46
+ #
47
47
  # To install into a Rails app, include this line in your
48
48
  # config/application.rb:
49
49
  # require 'sawmill/stats_railtie'
50
50
  # It should appear before your application configuration.
51
- #
51
+ #
52
52
  # You can then configure the stats logs using the standard rails
53
53
  # configuration mechanism. The configuration lives in the
54
54
  # config.sawmill_stats configuration namespace. See
55
55
  # Sawmill::StatsRailtie::Configuration for the list of options.
56
-
56
+
57
57
  class StatsRailtie < ::Rails::Railtie
58
-
59
-
58
+
59
+
60
60
  # Configuration options. These are attributes of config.sawmill_stats.
61
-
61
+
62
62
  class Configuration
63
-
63
+
64
64
  def initialize # :nodoc:
65
65
  @logfile = ::STDERR
66
66
  @fractional_second_digits = 2
@@ -79,11 +79,11 @@ module Sawmill
79
79
  @post_logger = nil
80
80
  @generated_logger = nil
81
81
  end
82
-
82
+
83
83
  # The log file to write to. This should be either an IO object, or
84
84
  # a Sawmill::Rotater. Default is STDERR.
85
85
  attr_accessor :logfile
86
-
86
+
87
87
  # This option is passed to Sawmill::EntryProcessor::Format::new
88
88
  attr_accessor :fractional_second_digits
89
89
  # This option is passed to Sawmill::EntryProcessor::Format::new
@@ -94,12 +94,12 @@ module Sawmill
94
94
  attr_accessor :iso_8601_time
95
95
  # This option is passed to Sawmill::EntryProcessor::Format::new
96
96
  attr_accessor :length_limit
97
-
97
+
98
98
  # This option is passed to Sawmill::Logger::new
99
99
  attr_accessor :level
100
100
  # This option is passed to Sawmill::Logger::new
101
101
  attr_accessor :progname
102
-
102
+
103
103
  # This option is passed to Sawmill::StatsMiddleware::new
104
104
  attr_accessor :stats_data_key
105
105
  # This option is passed to Sawmill::StatsMiddleware::new
@@ -110,11 +110,11 @@ module Sawmill
110
110
  attr_accessor :elapsed_time_stat
111
111
  # This option is passed to Sawmill::StatsMiddleware::new
112
112
  attr_accessor :request_id_stat
113
-
113
+
114
114
  # Access the logger after it is generated
115
115
  attr_reader :generated_logger
116
-
117
-
116
+
117
+
118
118
  def pre_logger(proc_=false, &block_)
119
119
  if block_
120
120
  @pre_logger = block_
@@ -124,7 +124,7 @@ module Sawmill
124
124
  @pre_logger
125
125
  end
126
126
  attr_writer :pre_logger
127
-
127
+
128
128
  def post_logger(proc_=false, &block_)
129
129
  if block_
130
130
  @post_logger = block_
@@ -134,17 +134,17 @@ module Sawmill
134
134
  @post_logger
135
135
  end
136
136
  attr_writer :post_logger
137
-
137
+
138
138
  def _set_generated_logger(logger_) # :nodoc:
139
139
  @generated_logger = logger_
140
140
  end
141
-
141
+
142
142
  end
143
-
144
-
143
+
144
+
145
145
  config.sawmill_stats = Configuration.new
146
-
147
-
146
+
147
+
148
148
  initializer :initialize_sawmill_stats, :before => :initialize_logger do |app_|
149
149
  main_config_ = app_.config
150
150
  stats_config_ = main_config_.sawmill_stats
@@ -171,9 +171,9 @@ module Sawmill
171
171
  :pre_logger => stats_config_.pre_logger,
172
172
  :post_logger => stats_config_.post_logger)
173
173
  end
174
-
175
-
174
+
175
+
176
176
  end
177
-
178
-
177
+
178
+
179
179
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill heap 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
@@ -35,41 +35,41 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module Util
40
-
41
-
40
+
41
+
42
42
  # A simple heap class.
43
-
43
+
44
44
  class Heap
45
-
46
-
45
+
46
+
47
47
  # Create a new heap.
48
-
48
+
49
49
  def initialize(data_=nil, &block_)
50
50
  @_heap = data_ || []
51
51
  @_comparator = block_ || ::Proc.new{ |a_,b_| a_ <=> b_ }
52
52
  end
53
-
54
-
53
+
54
+
55
55
  def merge(enum_)
56
56
  enum_.each{ |value_| add(value_) }
57
57
  self
58
58
  end
59
-
60
-
59
+
60
+
61
61
  def add(value_)
62
62
  @_heap << value_
63
63
  _sift_up(@_heap.length-1)
64
64
  self
65
65
  end
66
-
67
-
66
+
67
+
68
68
  def <<(value_)
69
69
  add(value_)
70
70
  end
71
-
72
-
71
+
72
+
73
73
  def remove
74
74
  ret_ = @_heap[0]
75
75
  if @_heap.length > 1
@@ -80,37 +80,37 @@ module Sawmill
80
80
  end
81
81
  ret_
82
82
  end
83
-
84
-
83
+
84
+
85
85
  def peek
86
86
  @_heap[0]
87
87
  end
88
-
89
-
88
+
89
+
90
90
  def size
91
91
  @_heap.size
92
92
  end
93
-
94
-
93
+
94
+
95
95
  def empty?
96
96
  @_heap.empty?
97
97
  end
98
-
99
-
98
+
99
+
100
100
  def clear
101
101
  @_heap.clear
102
102
  end
103
-
104
-
103
+
104
+
105
105
  def each!
106
106
  while !empty?
107
107
  yield(remove)
108
108
  end
109
109
  end
110
-
111
-
110
+
111
+
112
112
  private
113
-
113
+
114
114
  def _sift_up(start_) # :nodoc:
115
115
  while start_ > 0
116
116
  parent_ = (start_ + 1) / 2 - 1
@@ -122,8 +122,8 @@ module Sawmill
122
122
  end
123
123
  end
124
124
  end
125
-
126
-
125
+
126
+
127
127
  def _sift_down(start_) # :nodoc:
128
128
  length_ = self.size
129
129
  while length_ >= (child2_ = (start_ + 1) * 2)
@@ -143,11 +143,11 @@ module Sawmill
143
143
  end
144
144
  end
145
145
  end
146
-
147
-
146
+
147
+
148
148
  end
149
-
150
-
149
+
150
+
151
151
  end
152
-
152
+
153
153
  end
@@ -1,15 +1,15 @@
1
1
  # -----------------------------------------------------------------------------
2
- #
2
+ #
3
3
  # Sawmill tools for building processors
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,15 +35,15 @@
35
35
 
36
36
 
37
37
  module Sawmill
38
-
38
+
39
39
  module Util
40
-
41
-
40
+
41
+
42
42
  # Some miscellaneous tools for building processors
43
-
43
+
44
44
  module ProcessorTools
45
-
46
-
45
+
46
+
47
47
  def self.collect_finish_values(children_)
48
48
  ret_ = nil
49
49
  children_.each do |child_|
@@ -61,11 +61,11 @@ module Sawmill
61
61
  end
62
62
  ret_
63
63
  end
64
-
65
-
64
+
65
+
66
66
  end
67
-
68
-
67
+
68
+
69
69
  end
70
-
70
+
71
71
  end