sawmill 0.1.13 → 0.1.14

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.
data/History.rdoc CHANGED
@@ -1,5 +1,11 @@
1
- === 0.1.13 / 2011-06-23
1
+ === 0.1.14 / 2011-10-24
2
2
 
3
+ * Support for stats logs.
4
+
5
+ === 0.1.13 / 2011-07-16
6
+
7
+ * Rack middleware supports elapsed time attribute.
8
+ * Rack middleware can run pre-request and post-request logging tasks.
3
9
  * A .gemspec file is now available for gem building and bundler git integration.
4
10
  * Cleaned up docs a little
5
11
 
data/Version CHANGED
@@ -1 +1 @@
1
- 0.1.13
1
+ 0.1.14
data/lib/sawmill.rb CHANGED
@@ -37,45 +37,46 @@
37
37
  require 'blockenspiel'
38
38
 
39
39
 
40
- dir_ = ::File.expand_path('sawmill', ::File.dirname(__FILE__))
40
+ module Sawmill
41
+ end
41
42
 
42
- includes_ = [
43
- 'version',
44
- 'util/queue',
45
- 'util/heap',
46
- 'util/processor_tools',
47
- 'errors',
48
- 'level',
49
- 'entry',
50
- 'entry_classifier',
51
- 'entry_processor',
52
- 'entry_processor/conditionals',
53
- 'entry_processor/simple_queue',
54
- 'entry_processor/filter_by_basic_fields',
55
- 'entry_processor/filter_by_block',
56
- 'entry_processor/build_records',
57
- 'entry_processor/format',
58
- 'entry_processor/count_entries',
59
- 'entry_processor/compile_report',
60
- 'record',
61
- 'record_processor',
62
- 'record_processor/conditionals',
63
- 'record_processor/filter_by_record_id',
64
- 'record_processor/filter_by_attributes',
65
- 'record_processor/filter_by_block',
66
- 'record_processor/simple_queue',
67
- 'record_processor/decompose',
68
- 'record_processor/format',
69
- 'record_processor/count_records',
70
- 'record_processor/compile_report',
71
- 'parser',
72
- 'multi_parser',
73
- 'logger',
74
- 'rotater',
75
- 'rotater/base',
76
- 'rotater/date_based_log_file',
77
- 'rotater/shifting_log_file',
78
- 'log_record_middleware',
79
- 'interface',
80
- ]
81
- includes_.each{ |file_| require "#{dir_}/#{file_}" }
43
+
44
+ require 'sawmill/version'
45
+ require 'sawmill/util/queue'
46
+ require 'sawmill/util/heap'
47
+ require 'sawmill/util/processor_tools'
48
+ require 'sawmill/errors'
49
+ require 'sawmill/level'
50
+ require 'sawmill/entry'
51
+ require 'sawmill/entry_classifier'
52
+ require 'sawmill/entry_processor'
53
+ require 'sawmill/entry_processor/conditionals'
54
+ require 'sawmill/entry_processor/simple_queue'
55
+ require 'sawmill/entry_processor/filter_by_basic_fields'
56
+ require 'sawmill/entry_processor/filter_by_block'
57
+ require 'sawmill/entry_processor/build_records'
58
+ require 'sawmill/entry_processor/format'
59
+ require 'sawmill/entry_processor/count_entries'
60
+ require 'sawmill/entry_processor/compile_report'
61
+ require 'sawmill/entry_processor/interpret_stats'
62
+ require 'sawmill/record'
63
+ require 'sawmill/record_processor'
64
+ require 'sawmill/record_processor/conditionals'
65
+ require 'sawmill/record_processor/filter_by_record_id'
66
+ require 'sawmill/record_processor/filter_by_attributes'
67
+ require 'sawmill/record_processor/filter_by_block'
68
+ require 'sawmill/record_processor/simple_queue'
69
+ require 'sawmill/record_processor/decompose'
70
+ require 'sawmill/record_processor/format'
71
+ require 'sawmill/record_processor/count_records'
72
+ require 'sawmill/record_processor/compile_report'
73
+ require 'sawmill/parser'
74
+ require 'sawmill/multi_parser'
75
+ require 'sawmill/logger'
76
+ require 'sawmill/rotater'
77
+ require 'sawmill/rotater/base'
78
+ require 'sawmill/rotater/date_based_log_file'
79
+ require 'sawmill/rotater/shifting_log_file'
80
+ require 'sawmill/log_record_middleware'
81
+ require 'sawmill/stats_middleware'
82
+ require 'sawmill/interface'
@@ -0,0 +1,79 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Sawmill entry processor that interprets a stats log
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2009 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ module Sawmill
38
+
39
+ module EntryProcessor
40
+
41
+
42
+ # This processor interprets a stats log.
43
+
44
+ class InterpretStats < Base
45
+
46
+
47
+ # Create a stats log interpreter.
48
+
49
+ def initialize(opts_={}, &block_)
50
+ @handler = opts_[:handler] || block_ || method(:handle_data)
51
+ end
52
+
53
+
54
+ def message(entry_)
55
+ data_ = ::JSON.parse(entry_.message) rescue nil
56
+ if data_.is_a?(::Hash)
57
+ @handler.call(data_)
58
+ else
59
+ nil
60
+ end
61
+ end
62
+
63
+
64
+ def handle_data(data_)
65
+ true
66
+ end
67
+
68
+
69
+ def finish
70
+ @handler.call(nil)
71
+ end
72
+
73
+
74
+ end
75
+
76
+
77
+ end
78
+
79
+ end
@@ -93,9 +93,9 @@ module Sawmill
93
93
  begin
94
94
  return @app.call(env_)
95
95
  ensure
96
- if @post_logger
97
- @post_logger.call(@logger, env_)
98
- end
96
+ if @post_logger
97
+ @post_logger.call(@logger, env_)
98
+ end
99
99
  end_time_ = ::Time.now.utc
100
100
  if @end_time_attribute
101
101
  @logger.set_attribute(@end_time_attribute, end_time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % end_time_.usec) + 'Z')
@@ -64,8 +64,6 @@ module Sawmill
64
64
 
65
65
  def initialize # :nodoc:
66
66
  @logfile = ::STDERR
67
- @formatter_options = {}
68
- @logger_options = {}
69
67
  @include_id = false
70
68
  @fractional_second_digits = 2
71
69
  @level_width = nil
@@ -122,6 +120,7 @@ module Sawmill
122
120
  # This option is passed to Sawmill::LogRecordMiddleware::new
123
121
  attr_accessor :elapsed_time_attribute
124
122
 
123
+
125
124
  def pre_logger(proc_=false, &block_)
126
125
  if block_
127
126
  @pre_logger = block_
@@ -151,27 +150,28 @@ module Sawmill
151
150
  initializer :initialize_sawmill, :before => :initialize_logger do |app_|
152
151
  myconfig_ = app_.config.sawmill
153
152
  formatter_ = Formatter.new(myconfig_.logfile || ::STDERR,
154
- :include_id => myconfig_.include_id,
155
- :fractional_second_digits => myconfig_.fractional_second_digits,
156
- :level_width => myconfig_.level_width,
157
- :local_time => myconfig_.local_time,
158
- :iso_8601_time => myconfig_.iso_8601_time,
159
- :length_limit => myconfig_.length_limit)
160
- logger_ = Logger.new(:processor => formatter_,
161
- :level => myconfig_.level,
162
- :attribute_level => myconfig_.attribute_level,
163
- :progname => myconfig_.progname,
164
- :record_progname => myconfig_.record_progname,
165
- :record_id_generator => myconfig_.record_id_generator)
153
+ :include_id => myconfig_.include_id,
154
+ :fractional_second_digits => myconfig_.fractional_second_digits,
155
+ :level_width => myconfig_.level_width,
156
+ :local_time => myconfig_.local_time,
157
+ :iso_8601_time => myconfig_.iso_8601_time,
158
+ :length_limit => myconfig_.length_limit)
159
+ logger_ = Logger.new(
160
+ :processor => formatter_,
161
+ :level => myconfig_.level,
162
+ :attribute_level => myconfig_.attribute_level,
163
+ :progname => myconfig_.progname,
164
+ :record_progname => myconfig_.record_progname,
165
+ :record_id_generator => myconfig_.record_id_generator)
166
166
  app_.config.logger = logger_
167
167
  app_.config.middleware.swap(::Rails::Rack::Logger,
168
- ::Sawmill::LogRecordMiddleware, logger_,
169
- :request_id_key => myconfig_.request_id_key,
170
- :start_time_attribute => myconfig_.start_time_attribute,
171
- :end_time_attribute => myconfig_.end_time_attribute,
172
- :elapsed_time_attribute => myconfig_.elapsed_time_attribute,
173
- :pre_logger => myconfig_.pre_logger,
174
- :post_logger => myconfig_.post_logger)
168
+ ::Sawmill::LogRecordMiddleware, logger_,
169
+ :request_id_key => myconfig_.request_id_key,
170
+ :start_time_attribute => myconfig_.start_time_attribute,
171
+ :end_time_attribute => myconfig_.end_time_attribute,
172
+ :elapsed_time_attribute => myconfig_.elapsed_time_attribute,
173
+ :pre_logger => myconfig_.pre_logger,
174
+ :post_logger => myconfig_.post_logger)
175
175
  end
176
176
 
177
177
 
@@ -0,0 +1,138 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Sawmill stats middleware class
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2009 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ module Sawmill
38
+
39
+
40
+ # A Rack middleware that writes a stats log.
41
+ # Insert this in your Rack stack to generate a stats log.
42
+
43
+ class StatsMiddleware
44
+
45
+
46
+ # Create a middleware object for Rack.
47
+ #
48
+ # If you do not provide a logger object, one will be generated for you
49
+ # that simply logs to STDOUT.
50
+ #
51
+ # Recognized options include:
52
+ #
53
+ # [<tt>:level</tt>]
54
+ # The level to log at. Default is <tt>:ANY</tt>.
55
+ # [<tt>:stats_data_key</tt>]
56
+ # The name of a rack environment key where the stats data should
57
+ # be stored. If not specified, defaults to "sawmill.stats_data".
58
+ # [<tt>:record_id_key</tt>]
59
+ # The name of a rack environment key where the record ID can be
60
+ # obtained. If not specified, defaults to "sawmill.record_id".
61
+ # [<tt>:start_time_stat</tt>]
62
+ # If present, stores the starting timestamp for the request in the
63
+ # given stat key. If absent, does not store this information.
64
+ # [<tt>:end_time_stat</tt>]
65
+ # If present, stores the ending timestamp for the request in the
66
+ # given stat key. If absent, does not store this information.
67
+ # [<tt>:elapsed_time_stat</tt>]
68
+ # If present, stores the elapsed time for the request in the
69
+ # given stat key. If absent, does not store this information.
70
+ # [<tt>:log_record_id_stat</tt>]
71
+ # If present, stores the log record ID for the request in the
72
+ # given stat key. If absent, does not store this information.
73
+ # [<tt>:pre_logger</tt>]
74
+ # A proc that is called at the start of the request, and passed the
75
+ # logger and the rack environment. Optional.
76
+ # If a proc is provided and returns false, then stats logging is
77
+ # canceled for this request. Furthermore, any post_logger will
78
+ # not be called.
79
+ # [<tt>:post_logger</tt>]
80
+ # A proc that is called at the end of the request, and passed the
81
+ # logger and the rack environment. Optional.
82
+ # If a proc is provided and returns false, then stats logging is
83
+ # canceled for this request.
84
+
85
+ def initialize(app_, logger_=nil, level_=nil, opts_={})
86
+ @app = app_
87
+ @logger = logger_ || Logger.new(:progname => 'stats', :processor => Formatter.new(::STDOUT))
88
+ @level = level_ || :ANY
89
+ @stats_data_key = opts_[:stats_data_key] || 'sawmill.stats_data'
90
+ @record_id_key = opts_[:record_id_key] || 'sawmill.record_id'
91
+ @start_time_stat = opts_[:start_time_stat]
92
+ @end_time_stat = opts_[:end_time_stat]
93
+ @elapsed_time_stat = opts_[:elapsed_time_stat]
94
+ @log_record_id_stat = opts_[:log_record_id_stat]
95
+ @pre_logger = opts_[:pre_logger]
96
+ @post_logger = opts_[:post_logger]
97
+ end
98
+
99
+
100
+ def call(env_)
101
+ env_[@stats_data_key] = stats_data_ = {}
102
+ start_time_ = ::Time.now.utc
103
+ if @start_time_stat
104
+ stats_data_[@start_time_stat.to_s] = start_time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % start_time_.usec) + 'Z'
105
+ end
106
+ enable_log_ = true
107
+ if @pre_logger
108
+ enable_log_ &&= @pre_logger.call(stats_data_, env_)
109
+ end
110
+ begin
111
+ return @app.call(env_)
112
+ ensure
113
+ if enable_log_
114
+ if @log_record_id_stat
115
+ stats_data_[@log_record_id_stat.to_s] = env_[@record_id_key]
116
+ end
117
+ if @post_logger
118
+ enable_log_ &&= @post_logger.call(stats_data_, env_)
119
+ end
120
+ if enable_log_
121
+ end_time_ = ::Time.now.utc
122
+ if @end_time_stat
123
+ stats_data_[@end_time_stat.to_s] = end_time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % end_time_.usec) + 'Z'
124
+ end
125
+ if @elapsed_time_stat
126
+ stats_data_[@elapsed_time_stat.to_s] = end_time_ - start_time_
127
+ end
128
+ @logger.add(@level, ::JSON.dump(stats_data_))
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+
135
+ end
136
+
137
+
138
+ end
@@ -0,0 +1,179 @@
1
+ # -----------------------------------------------------------------------------
2
+ #
3
+ # Sawmill railtie
4
+ #
5
+ # -----------------------------------------------------------------------------
6
+ # Copyright 2009 Daniel Azuma
7
+ #
8
+ # All rights reserved.
9
+ #
10
+ # Redistribution and use in source and binary forms, with or without
11
+ # modification, are permitted provided that the following conditions are met:
12
+ #
13
+ # * Redistributions of source code must retain the above copyright notice,
14
+ # this list of conditions and the following disclaimer.
15
+ # * Redistributions in binary form must reproduce the above copyright notice,
16
+ # this list of conditions and the following disclaimer in the documentation
17
+ # and/or other materials provided with the distribution.
18
+ # * Neither the name of the copyright holder, nor the names of any other
19
+ # contributors to this software, may be used to endorse or promote products
20
+ # derived from this software without specific prior written permission.
21
+ #
22
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ # POSSIBILITY OF SUCH DAMAGE.
33
+ # -----------------------------------------------------------------------------
34
+ ;
35
+
36
+
37
+ require 'sawmill'
38
+ require 'rails/railtie'
39
+
40
+
41
+ module Sawmill
42
+
43
+
44
+ # Railtie that sets up a stats logger. Installs a
45
+ # Sawmill::StatsMiddleware to enable a stats log.
46
+ #
47
+ # To install into a Rails app, include this line in your
48
+ # config/application.rb:
49
+ # require 'sawmill/stats_railtie'
50
+ # It should appear before your application configuration.
51
+ #
52
+ # You can then configure the stats logs using the standard rails
53
+ # configuration mechanism. The configuration lives in the
54
+ # config.sawmill_stats configuration namespace. See
55
+ # Sawmill::StatsRailtie::Configuration for the list of options.
56
+
57
+ class StatsRailtie < ::Rails::Railtie
58
+
59
+
60
+ # Configuration options. These are attributes of config.sawmill_stats.
61
+
62
+ class Configuration
63
+
64
+ def initialize # :nodoc:
65
+ @logfile = ::STDERR
66
+ @fractional_second_digits = 2
67
+ @level_width = nil
68
+ @local_time = false
69
+ @iso_8601_time = false
70
+ @length_limit = nil
71
+ @level = :ANY
72
+ @progname = 'rails'
73
+ @stats_data_key = 'sawmill.stats_hash'
74
+ @start_time_stat = nil
75
+ @end_time_stat = nil
76
+ @elapsed_time_stat = nil
77
+ @log_record_id_stat = nil
78
+ @pre_logger = nil
79
+ @post_logger = nil
80
+ @generated_logger = nil
81
+ end
82
+
83
+ # The log file to write to. This should be either an IO object, or
84
+ # a Sawmill::Rotater. Default is STDERR.
85
+ attr_accessor :logfile
86
+
87
+ # This option is passed to Sawmill::EntryProcessor::Format::new
88
+ attr_accessor :fractional_second_digits
89
+ # This option is passed to Sawmill::EntryProcessor::Format::new
90
+ attr_accessor :level_width
91
+ # This option is passed to Sawmill::EntryProcessor::Format::new
92
+ attr_accessor :local_time
93
+ # This option is passed to Sawmill::EntryProcessor::Format::new
94
+ attr_accessor :iso_8601_time
95
+ # This option is passed to Sawmill::EntryProcessor::Format::new
96
+ attr_accessor :length_limit
97
+
98
+ # This option is passed to Sawmill::Logger::new
99
+ attr_accessor :level
100
+ # This option is passed to Sawmill::Logger::new
101
+ attr_accessor :progname
102
+
103
+ # This option is passed to Sawmill::StatsMiddleware::new
104
+ attr_accessor :stats_data_key
105
+ # This option is passed to Sawmill::StatsMiddleware::new
106
+ attr_accessor :start_time_stat
107
+ # This option is passed to Sawmill::StatsMiddleware::new
108
+ attr_accessor :end_time_stat
109
+ # This option is passed to Sawmill::StatsMiddleware::new
110
+ attr_accessor :elapsed_time_stat
111
+ # This option is passed to Sawmill::StatsMiddleware::new
112
+ attr_accessor :log_record_id_stat
113
+
114
+ # Access the logger after it is generated
115
+ attr_reader :generated_logger
116
+
117
+
118
+ def pre_logger(proc_=false, &block_)
119
+ if block_
120
+ @pre_logger = block_
121
+ elsif proc_ != false
122
+ @pre_logger = proc_
123
+ end
124
+ @pre_logger
125
+ end
126
+ attr_writer :pre_logger
127
+
128
+ def post_logger(proc_=false, &block_)
129
+ if block_
130
+ @post_logger = block_
131
+ elsif proc_ != false
132
+ @post_logger = proc_
133
+ end
134
+ @post_logger
135
+ end
136
+ attr_writer :post_logger
137
+
138
+ def _set_generated_logger(logger_) # :nodoc:
139
+ @generated_logger = logger_
140
+ end
141
+
142
+ end
143
+
144
+
145
+ config.sawmill_stats = Configuration.new
146
+
147
+
148
+ initializer :initialize_sawmill_stats, :before => :initialize_logger do |app_|
149
+ main_config_ = app_.config
150
+ stats_config_ = main_config_.sawmill_stats
151
+ sawmill_config_ = main_config_.respond_to?(:sawmill) ? main_config_.sawmill : nil
152
+ formatter_ = Formatter.new(stats_config_.logfile || ::STDERR,
153
+ :fractional_second_digits => stats_config_.fractional_second_digits,
154
+ :level_width => stats_config_.level_width,
155
+ :local_time => stats_config_.local_time,
156
+ :iso_8601_time => stats_config_.iso_8601_time,
157
+ :length_limit => stats_config_.length_limit)
158
+ logger_ = Logger.new(
159
+ :processor => formatter_,
160
+ :level => stats_config_.level,
161
+ :progname => stats_config_.progname)
162
+ stats_config_._set_generated_logger(logger_)
163
+ app_.config.middleware.insert_after(::Rack::Runtime,
164
+ ::Sawmill::StatsMiddleware, logger_, stats_config_.level,
165
+ :log_record_id_stat => sawmill_config_ && stats_config_.log_record_id_stat ?
166
+ stats_config_.log_record_id_stat : nil,
167
+ :stats_data_key => stats_config_.stats_data_key,
168
+ :start_time_stat => stats_config_.start_time_stat,
169
+ :end_time_stat => stats_config_.end_time_stat,
170
+ :elapsed_time_stat => stats_config_.elapsed_time_stat,
171
+ :pre_logger => stats_config_.pre_logger,
172
+ :post_logger => stats_config_.post_logger)
173
+ end
174
+
175
+
176
+ end
177
+
178
+
179
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sawmill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-17 00:00:00.000000000 Z
12
+ date: 2011-10-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blockenspiel
16
- requirement: &2153258020 !ruby/object:Gem::Requirement
16
+ requirement: &2153021800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.4.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153258020
24
+ version_requirements: *2153021800
25
25
  description: Sawmill is a logging and log analysis system for Ruby. It extends the
26
26
  basic Ruby logging facility with log records and parsing abilities.
27
27
  email: dazuma@gmail.com
@@ -40,6 +40,7 @@ files:
40
40
  - lib/sawmill/entry_processor/filter_by_basic_fields.rb
41
41
  - lib/sawmill/entry_processor/filter_by_block.rb
42
42
  - lib/sawmill/entry_processor/format.rb
43
+ - lib/sawmill/entry_processor/interpret_stats.rb
43
44
  - lib/sawmill/entry_processor/simple_queue.rb
44
45
  - lib/sawmill/entry_processor.rb
45
46
  - lib/sawmill/errors.rb
@@ -65,6 +66,8 @@ files:
65
66
  - lib/sawmill/rotater/date_based_log_file.rb
66
67
  - lib/sawmill/rotater/shifting_log_file.rb
67
68
  - lib/sawmill/rotater.rb
69
+ - lib/sawmill/stats_middleware.rb
70
+ - lib/sawmill/stats_railtie.rb
68
71
  - lib/sawmill/util/heap.rb
69
72
  - lib/sawmill/util/processor_tools.rb
70
73
  - lib/sawmill/util/queue.rb
@@ -101,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
104
  version: 1.3.1
102
105
  requirements: []
103
106
  rubyforge_project: virtuoso
104
- rubygems_version: 1.8.5
107
+ rubygems_version: 1.8.7
105
108
  signing_key:
106
109
  specification_version: 3
107
110
  summary: Sawmill is a logging and log analysis system for Ruby.