sawmill 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 0.1.13 / 2011-06-23
2
+
3
+ * A .gemspec file is now available for gem building and bundler git integration.
4
+ * Cleaned up docs a little
5
+
1
6
  === 0.1.12 / 2010-11-01
2
7
 
3
8
  * A date-based rotater can now force log files to be written to by only one process. Useful in environments where you have an unknown number of processes(i.e. a Passenger-based deployment), each of which needs a separate log file.
@@ -27,7 +27,7 @@ Sawmill is an extension to the standard ruby Logger mechanism that enables autom
27
27
  === Requirements
28
28
 
29
29
  * Ruby 1.8.7 or later (Ruby 1.9.2 or later recommended), or JRuby 1.4 or later.
30
- * Blockenspiel 0.4.1 or later.
30
+ * Blockenspiel 0.4.3 or later.
31
31
 
32
32
  === Installation
33
33
 
@@ -55,7 +55,7 @@ Development of Sawmill is sponsored by GeoPage (http://www.geopage.com/).
55
55
 
56
56
  === License
57
57
 
58
- Copyright 2009-2010 Daniel Azuma.
58
+ Copyright 2009-2011 Daniel Azuma.
59
59
 
60
60
  All rights reserved.
61
61
 
data/Version CHANGED
@@ -1 +1 @@
1
- 0.1.12
1
+ 0.1.13
@@ -49,7 +49,7 @@ module Sawmill
49
49
  #
50
50
  # Recognized options include:
51
51
  #
52
- # <tt>:emit_incomplete_records_on_finish</tt>::
52
+ # [<tt>:emit_incomplete_records_on_finish</tt>]
53
53
  # When the processor is finished, any records that are still not
54
54
  # complete will be emitted to the record processor anyway, even
55
55
  # in their incomplete state.
@@ -50,16 +50,16 @@ module Sawmill
50
50
  #
51
51
  # Recognized options include:
52
52
  #
53
- # <tt>:postprocessor</tt>::
53
+ # [<tt>:postprocessor</tt>]
54
54
  # Postprocessor proc for individual reports.
55
55
  # See to_postprocess_value.
56
- # <tt>:separator</tt>::
56
+ # [<tt>:separator</tt>]
57
57
  # Separator string to be inserted between individual reports.
58
58
  # Default is a single newline.
59
- # <tt>:header</tt>::
59
+ # [<tt>:header</tt>]
60
60
  # Header string for the final compiled report.
61
61
  # Default is the empty string.
62
- # <tt>:footer</tt>::
62
+ # [<tt>:footer</tt>]
63
63
  # Footer string for the final compiled report.
64
64
  # Default is the empty string.
65
65
 
@@ -48,18 +48,18 @@ module Sawmill
48
48
  #
49
49
  # Recognized options include:
50
50
  #
51
- # <tt>:label</tt>::
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
- # <tt>:omit_unknown_data</tt>::
56
+ # [<tt>:omit_unknown_data</tt>]
57
57
  # If set to true, omits unknown_data from the count.
58
58
  # Default is false.
59
- # <tt>:omit_attributes</tt>::
59
+ # [<tt>:omit_attributes</tt>]
60
60
  # If set to true, omits attributes from the count.
61
61
  # Default is false.
62
- # <tt>:omit_record_delimiters</tt>::
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
 
@@ -52,29 +52,29 @@ module Sawmill
52
52
  #
53
53
  # Recognized options include:
54
54
  #
55
- # <tt>:level</tt>::
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
58
58
  # represents a level. If set to nil or not specified, this filter
59
59
  # does not check the level.
60
- # <tt>:progname</tt>::
60
+ # [<tt>:progname</tt>]
61
61
  # Progname filter. This can be either a string or a Regexp. If set
62
62
  # to nil or not specified, this filter does not check the progname.
63
- # <tt>:accept_record_delimiters</tt>::
63
+ # [<tt>:accept_record_delimiters</tt>]
64
64
  # If set to true, accepts all begin_record and end_record entries
65
65
  # regardless of the level or progname. If set to false, accepts no
66
66
  # such entries. Otherwise, if not specified, those entries are
67
67
  # subject to the usual level and progname filters.
68
- # <tt>:accept_attributes</tt>::
68
+ # [<tt>:accept_attributes</tt>]
69
69
  # If set to true, accepts all attribute and multi_attribute entries
70
70
  # regardless of the level or progname. If set to false, accepts no
71
71
  # such entries. Otherwise, if not specified, those entries are
72
72
  # subject to the usual level and progname filters.
73
- # <tt>:accept_incomparable_levels</tt>::
73
+ # [<tt>:accept_incomparable_levels</tt>]
74
74
  # If set to true, accepts entries whose level is not comparable to
75
75
  # the given <tt>:level</tt> setting. Otherwise, rejects all such
76
76
  # entries.
77
- # <tt>:accept_unknown</tt>::
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
 
@@ -52,20 +52,20 @@ module Sawmill
52
52
  #
53
53
  # Recognized options include:
54
54
  #
55
- # <tt>:include_id</tt>::
55
+ # [<tt>:include_id</tt>]
56
56
  # Include the record ID in every log entry. Default is false.
57
- # <tt>:fractional_second_digits</tt>::
57
+ # [<tt>:fractional_second_digits</tt>]
58
58
  # Number of digits of fractional seconds to display in timestamps.
59
59
  # Default is 2. Accepted values are 0 to 6.
60
- # <tt>:level_width</tt>::
60
+ # [<tt>:level_width</tt>]
61
61
  # Column width of the level field.
62
- # <tt>:local_time</tt>::
62
+ # [<tt>:local_time</tt>]
63
63
  # If true, outputs local time with the timezone offset indicator.
64
64
  # If false (the default), outputs UTC.
65
- # <tt>:iso_8601_time</tt>::
65
+ # [<tt>:iso_8601_time</tt>]
66
66
  # If true, outputs time in strict ISO 8601 format.
67
67
  # If false (the default), outputs a slightly more readable format.
68
- # <tt>:length_limit</tt>::
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
 
@@ -49,10 +49,10 @@ module Sawmill
49
49
  #
50
50
  # Recognized options include:
51
51
  #
52
- # <tt>:limit</tt>::
52
+ # [<tt>:limit</tt>]
53
53
  # Size limit for the queue. If not specified, the queue can grow
54
54
  # arbitrarily large.
55
- # <tt>:drop_oldest</tt>::
55
+ # [<tt>:drop_oldest</tt>]
56
56
  # If set to true, then when an item is added to a full queue, the
57
57
  # oldest item is dropped. If set to false or not specified, then
58
58
  # the new item is not added.
@@ -50,39 +50,39 @@ module Sawmill
50
50
  # You may pass the same options taken by Sawmill::Logger#new and
51
51
  # Sawmill::EntryProcessor::Format#new, which are:
52
52
  #
53
- # <tt>:levels</tt>::
53
+ # [<tt>:levels</tt>]
54
54
  # Use a custom Sawmill::LevelGroup. Normally, you should leave this
55
55
  # set to the default, which is Sawmill::STANDARD_LEVELS.
56
- # <tt>:level</tt>::
56
+ # [<tt>:level</tt>]
57
57
  # Default level to use for log messages when no level is explicitly
58
58
  # provided. By default, this is set to the level group's default,
59
59
  # which in the case of the standard levels is :INFO.
60
- # <tt>:attribute_level</tt>::
60
+ # [<tt>:attribute_level</tt>]
61
61
  # Default level to use for attributes when no level is explicitly
62
62
  # provided. By default, this is set to the level group's highest,
63
63
  # level, which in the case of the standard levels is :ANY.
64
- # <tt>:progname</tt>::
64
+ # [<tt>:progname</tt>]
65
65
  # Progname to use in log messages. Default is "sawmill".
66
- # <tt>:record_progname</tt>::
66
+ # [<tt>:record_progname</tt>]
67
67
  # Progname to use in special log entries dealing with log records
68
68
  # (i.e. record delimiters and attribute messages). Default is the
69
69
  # same as the normal progname setting.
70
- # <tt>:record_id_generator</tt>::
70
+ # [<tt>:record_id_generator</tt>]
71
71
  # A proc that generates and returns a new record ID if one is not
72
72
  # explicitly passed into begin_record. If you do not provide a
73
73
  # generator, the default one is used, which generates an ID using the
74
74
  # variant 4 (random) UUID standard.
75
- # <tt>:include_id</tt>::
75
+ # [<tt>:include_id</tt>]
76
76
  # Write the record ID in every log entry. Default is false.
77
- # <tt>:fractional_second_digits</tt>::
77
+ # [<tt>:fractional_second_digits</tt>]
78
78
  # Number of digits of fractional seconds to write in timestamps.
79
79
  # Default is 2. Accepted values are 0 to 6.
80
- # <tt>:level_width</tt>::
80
+ # [<tt>:level_width</tt>]
81
81
  # Column width of the level field.
82
- # <tt>:local_time</tt>::
82
+ # [<tt>:local_time</tt>]
83
83
  # If true, outputs local time with the timezone offset indicator.
84
84
  # If false (the default), outputs UTC.
85
- # <tt>:iso_8601_time</tt>::
85
+ # [<tt>:iso_8601_time</tt>]
86
86
  # If true, outputs time in strict ISO 8601 format.
87
87
  # If false (the default), outputs a slightly more readable format.
88
88
 
@@ -120,51 +120,51 @@ module Sawmill
120
120
  # Sawmill::EntryProcessor::Format#new, Sawmill::Rotater#new, and
121
121
  # Sawmill::Rotater::ShiftingLogFile#new, which are:
122
122
  #
123
- # <tt>:levels</tt>::
123
+ # [<tt>:levels</tt>]
124
124
  # Use a custom Sawmill::LevelGroup. Normally, you should leave this
125
125
  # set to the default, which is Sawmill::STANDARD_LEVELS.
126
- # <tt>:level</tt>::
126
+ # [<tt>:level</tt>]
127
127
  # Default level to use for log messages when no level is explicitly
128
128
  # provided. By default, this is set to the level group's default,
129
129
  # which in the case of the standard levels is :INFO.
130
- # <tt>:attribute_level</tt>::
130
+ # [<tt>:attribute_level</tt>]
131
131
  # Default level to use for attributes when no level is explicitly
132
132
  # provided. By default, this is set to the level group's highest,
133
133
  # level, which in the case of the standard levels is :ANY.
134
- # <tt>:progname</tt>::
134
+ # [<tt>:progname</tt>]
135
135
  # Progname to use in log messages. Default is "sawmill".
136
- # <tt>:record_progname</tt>::
136
+ # [<tt>:record_progname</tt>]
137
137
  # Progname to use in special log entries dealing with log records
138
138
  # (i.e. record delimiters and attribute messages). Default is the
139
139
  # same as the normal progname setting.
140
- # <tt>:record_id_generator</tt>::
140
+ # [<tt>:record_id_generator</tt>]
141
141
  # A proc that generates and returns a new record ID if one is not
142
142
  # explicitly passed into begin_record. If you do not provide a
143
143
  # generator, the default one is used, which generates an ID using the
144
144
  # variant 4 (random) UUID standard.
145
- # <tt>:include_id</tt>::
145
+ # [<tt>:include_id</tt>]
146
146
  # Write the record ID in every log entry. Default is false.
147
- # <tt>:fractional_second_digits</tt>::
147
+ # [<tt>:fractional_second_digits</tt>]
148
148
  # Number of digits of fractional seconds to write in timestamps.
149
149
  # Default is 2. Accepted values are 0 to 6.
150
- # <tt>:level_width</tt>::
150
+ # [<tt>:level_width</tt>]
151
151
  # Column width of the level field.
152
- # <tt>:local_time</tt>::
152
+ # [<tt>:local_time</tt>]
153
153
  # If true, outputs local time with the timezone offset indicator.
154
154
  # If false (the default), outputs UTC.
155
- # <tt>:iso_8601_time</tt>::
155
+ # [<tt>:iso_8601_time</tt>]
156
156
  # If true, outputs time in strict ISO 8601 format.
157
157
  # If false (the default), outputs a slightly more readable format.
158
- # <tt>:omit_directives</tt>::
158
+ # [<tt>:omit_directives</tt>]
159
159
  # If true, omit standard logfile directives. Default is false.
160
- # <tt>:basedir</tt>::
160
+ # [<tt>:basedir</tt>]
161
161
  # The base directory used if the filepath is a relative path.
162
162
  # If not specified, the current working directory is used.
163
- # <tt>:history_size</tt>::
163
+ # [<tt>:history_size</tt>]
164
164
  # The maximum number of old logfiles (files with indexes) to
165
165
  # keep. Files beyond this history size will be automatically
166
166
  # deleted. Default is 1. This value must be at least 1.
167
- # <tt>:encoding</tt>::
167
+ # [<tt>:encoding</tt>]
168
168
  # Specify an encoding name for file data. (Ruby 1.9 only)
169
169
  # If not specified, uses the default external encoding.
170
170
 
@@ -188,54 +188,54 @@ module Sawmill
188
188
  # Sawmill::EntryProcessor::Format#new, Sawmill::Rotater#new, and
189
189
  # Sawmill::Rotater::DateBasedLogFile#new, which are:
190
190
  #
191
- # <tt>:levels</tt>::
191
+ # [<tt>:levels</tt>]
192
192
  # Use a custom Sawmill::LevelGroup. Normally, you should leave this
193
193
  # set to the default, which is Sawmill::STANDARD_LEVELS.
194
- # <tt>:level</tt>::
194
+ # [<tt>:level</tt>]
195
195
  # Default level to use for log messages when no level is explicitly
196
196
  # provided. By default, this is set to the level group's default,
197
197
  # which in the case of the standard levels is :INFO.
198
- # <tt>:attribute_level</tt>::
198
+ # [<tt>:attribute_level</tt>]
199
199
  # Default level to use for attributes when no level is explicitly
200
200
  # provided. By default, this is set to the level group's highest,
201
201
  # level, which in the case of the standard levels is :ANY.
202
- # <tt>:progname</tt>::
202
+ # [<tt>:progname</tt>]
203
203
  # Progname to use in log messages. Default is "sawmill".
204
- # <tt>:record_progname</tt>::
204
+ # [<tt>:record_progname</tt>]
205
205
  # Progname to use in special log entries dealing with log records
206
206
  # (i.e. record delimiters and attribute messages). Default is the
207
207
  # same as the normal progname setting.
208
- # <tt>:record_id_generator</tt>::
208
+ # [<tt>:record_id_generator</tt>]
209
209
  # A proc that generates and returns a new record ID if one is not
210
210
  # explicitly passed into begin_record. If you do not provide a
211
211
  # generator, the default one is used, which generates an ID using the
212
212
  # variant 4 (random) UUID standard.
213
- # <tt>:include_id</tt>::
213
+ # [<tt>:include_id</tt>]
214
214
  # Write the record ID in every log entry. Default is false.
215
- # <tt>:fractional_second_digits</tt>::
215
+ # [<tt>:fractional_second_digits</tt>]
216
216
  # Number of digits of fractional seconds to write in timestamps.
217
217
  # Default is 2. Accepted values are 0 to 6.
218
- # <tt>:level_width</tt>::
218
+ # [<tt>:level_width</tt>]
219
219
  # Column width of the level field.
220
- # <tt>:local_time</tt>::
220
+ # [<tt>:local_time</tt>]
221
221
  # If true, outputs local time with the timezone offset indicator.
222
222
  # If false (the default), outputs UTC.
223
- # <tt>:iso_8601_time</tt>::
223
+ # [<tt>:iso_8601_time</tt>]
224
224
  # If true, outputs time in strict ISO 8601 format.
225
225
  # If false (the default), outputs a slightly more readable format.
226
- # <tt>:omit_directives</tt>::
226
+ # [<tt>:omit_directives</tt>]
227
227
  # If true, omit standard logfile directives. Default is false.
228
- # <tt>:basedir</tt>::
228
+ # [<tt>:basedir</tt>]
229
229
  # The base directory used if the filepath is a relative path.
230
230
  # If not specified, the current working directory is used.
231
- # <tt>:name_suffix</tt>::
231
+ # [<tt>:name_suffix</tt>]
232
232
  # The logfile name suffix.
233
233
  # In the filename "rails.2009-10-11.log", the suffix is ".log".
234
234
  # If not specified, defaults to ".log".
235
- # <tt>:local_datestamps</tt>::
235
+ # [<tt>:local_datestamps</tt>]
236
236
  # If true, use the local timezone to create datestamps.
237
237
  # The default is to use UTC.
238
- # <tt>:encoding</tt>::
238
+ # [<tt>:encoding</tt>]
239
239
  # Specify an encoding name for file data. (Ruby 1.9 only)
240
240
  # If not specified, uses the default external encoding.
241
241
 
@@ -254,22 +254,22 @@ module Sawmill
254
254
  # You may pass the same options taken by Sawmill::MultiParser#new,
255
255
  # which are:
256
256
  #
257
- # <tt>:levels</tt>::
257
+ # [<tt>:levels</tt>]
258
258
  # Sawmill::LevelGroup to use to parse log levels.
259
259
  # If not specified, Sawmill::STANDARD_LEVELS is used by default.
260
- # <tt>:emit_incomplete_records_at_eof</tt>::
260
+ # [<tt>:emit_incomplete_records_at_eof</tt>]
261
261
  # If set to true, causes any incomplete log records to be emitted
262
262
  # in their incomplete state when EOF is reached on all streams.
263
263
  #
264
264
  # Additionally, these options are recognized:
265
265
  #
266
- # <tt>:encoding</tt>::
266
+ # [<tt>:encoding</tt>]
267
267
  # Specify an encoding for file data. (Ruby 1.9 only.)
268
268
  # You may specify an encoding name or an encoding object.
269
269
  # If not specified, reads raw bytes (e.g. defaults to 'ASCII-8BIT').
270
270
  # Note that the encoding may also be modified by the file itself,
271
271
  # if an appropriate parser directive is encountered.
272
- # <tt>:internal_encoding</tt>::
272
+ # [<tt>:internal_encoding</tt>]
273
273
  # Specify an encoding to transcode to. (Ruby 1.9 only.)
274
274
  # You may specify an encoding name or an encoding object.
275
275
  # If not specified, uses the encoding as read from the file.
@@ -287,22 +287,22 @@ module Sawmill
287
287
  # You may pass the same options taken by Sawmill::MultiParser#new,
288
288
  # which are:
289
289
  #
290
- # <tt>:levels</tt>::
290
+ # [<tt>:levels</tt>]
291
291
  # Sawmill::LevelGroup to use to parse log levels.
292
292
  # If not specified, Sawmill::STANDARD_LEVELS is used by default.
293
- # <tt>:emit_incomplete_records_at_eof</tt>::
293
+ # [<tt>:emit_incomplete_records_at_eof</tt>]
294
294
  # If set to true, causes any incomplete log records to be emitted
295
295
  # in their incomplete state when EOF is reached on all streams.
296
296
  #
297
297
  # Additionally, these options are recognized:
298
298
  #
299
- # <tt>:encoding</tt>::
299
+ # [<tt>:encoding</tt>]
300
300
  # Specify an encoding for file data. (Ruby 1.9 only.)
301
301
  # You may specify an encoding name or an encoding object.
302
302
  # If not specified, reads raw bytes (e.g. defaults to 'ASCII-8BIT').
303
303
  # Note that the encoding may also be modified by the file itself,
304
304
  # if an appropriate parser directive is encountered.
305
- # <tt>:internal_encoding</tt>::
305
+ # [<tt>:internal_encoding</tt>]
306
306
  # Specify an encoding to transcode to. (Ruby 1.9 only.)
307
307
  # You may specify an encoding name or an encoding object.
308
308
  # If not specified, uses the encoding as read from the file.
@@ -319,26 +319,26 @@ module Sawmill
319
319
  # You may pass the same options taken by Sawmill::MultiParser#new,
320
320
  # which are:
321
321
  #
322
- # <tt>:levels</tt>::
322
+ # [<tt>:levels</tt>]
323
323
  # Sawmill::LevelGroup to use to parse log levels.
324
324
  # If not specified, Sawmill::STANDARD_LEVELS is used by default.
325
- # <tt>:emit_incomplete_records_at_eof</tt>::
325
+ # [<tt>:emit_incomplete_records_at_eof</tt>]
326
326
  # If set to true, causes any incomplete log records to be emitted
327
327
  # in their incomplete state when EOF is reached on all streams.
328
328
  #
329
329
  # Additionally, these options are recognized:
330
330
  #
331
- # <tt>:finish</tt>::
331
+ # [<tt>:finish</tt>]
332
332
  # If set to true, the "finish" method is called on the processor
333
333
  # after all files have been parsed, and the return value is returned.
334
334
  # Otherwise, the processor is left open and nil is returned.
335
- # <tt>:encoding</tt>::
335
+ # [<tt>:encoding</tt>]
336
336
  # Specify an encoding for file data. (Ruby 1.9 only.)
337
337
  # You may specify an encoding name or an encoding object.
338
338
  # If not specified, reads raw bytes (e.g. defaults to 'ASCII-8BIT').
339
339
  # Note that the encoding may also be modified by the file itself,
340
340
  # if an appropriate parser directive is encountered.
341
- # <tt>:internal_encoding</tt>::
341
+ # [<tt>:internal_encoding</tt>]
342
342
  # Specify an encoding to transcode to. (Ruby 1.9 only.)
343
343
  # You may specify an encoding name or an encoding object.
344
344
  # If not specified, uses the encoding as read from the file.
@@ -231,9 +231,9 @@ module Sawmill
231
231
  #
232
232
  # You may also provide these options:
233
233
  #
234
- # <tt>:default</tt>::
234
+ # [<tt>:default</tt>]
235
235
  # If set to true, this level is made the default.
236
- # <tt>:methods</tt>::
236
+ # [<tt>:methods</tt>]
237
237
  # If set to an array of strings or methods, those method names are
238
238
  # mapped to this level. You may then use those methods in the
239
239
  # Sawmill::Logger class as a shortcut for creating log messages with
@@ -50,15 +50,24 @@ module Sawmill
50
50
  #
51
51
  # Recognized options include:
52
52
  #
53
- # <tt>:request_id_key</tt>::
53
+ # [<tt>:request_id_key</tt>]
54
54
  # The name of a rack environment key where the record ID should be
55
55
  # stored. If not specified, defaults to "sawmill.request_id".
56
- # <tt>:start_time_attribute</tt>::
56
+ # [<tt>:start_time_attribute</tt>]
57
57
  # If present, logs an attribute with this name with the starting
58
58
  # timestamp for the request. If absent, does not log this attribute.
59
- # <tt>:end_time_attribute</tt>::
59
+ # [<tt>:end_time_attribute</tt>]
60
60
  # If present, logs an attribute with this name with the ending
61
61
  # timestamp for the request. If absent, does not log this attribute.
62
+ # [<tt>:elapsed_time_attribute</tt>]
63
+ # If present, logs an attribute with this name with the elapsed time
64
+ # for the request, in seconds. If absent, does not log this attribute.
65
+ # [<tt>:pre_logger</tt>]
66
+ # A proc that is called at the start of the request, and passed the
67
+ # logger and the rack environment. Optional.
68
+ # [<tt>:post_logger</tt>]
69
+ # A proc that is called at the end of the request, and passed the
70
+ # logger and the rack environment. Optional.
62
71
 
63
72
  def initialize(app_, logger_=nil, opts_={})
64
73
  @app = app_
@@ -66,21 +75,33 @@ module Sawmill
66
75
  @request_id_key = opts_[:request_id_key] || 'sawmill.request_id'
67
76
  @start_time_attribute = opts_[:start_time_attribute]
68
77
  @end_time_attribute = opts_[:end_time_attribute]
78
+ @elapsed_time_attribute = opts_[:elapsed_time_attribute]
79
+ @pre_logger = opts_[:pre_logger]
80
+ @post_logger = opts_[:post_logger]
69
81
  end
70
82
 
71
83
 
72
84
  def call(env_)
73
85
  env_[@request_id_key] = @logger.begin_record
86
+ start_time_ = ::Time.now.utc
74
87
  if @start_time_attribute
75
- time_ = ::Time.now.utc
76
- @logger.set_attribute(@start_time_attribute, time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % time_.usec) + 'Z')
88
+ @logger.set_attribute(@start_time_attribute, start_time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % start_time_.usec) + 'Z')
89
+ end
90
+ if @pre_logger
91
+ @pre_logger.call(@logger, env_)
77
92
  end
78
93
  begin
79
94
  return @app.call(env_)
80
95
  ensure
96
+ if @post_logger
97
+ @post_logger.call(@logger, env_)
98
+ end
99
+ end_time_ = ::Time.now.utc
81
100
  if @end_time_attribute
82
- time_ = ::Time.now.utc
83
- @logger.set_attribute(@end_time_attribute, time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % time_.usec) + 'Z')
101
+ @logger.set_attribute(@end_time_attribute, end_time_.strftime('%Y-%m-%dT%H:%M:%S.') + ('%06d' % end_time_.usec) + 'Z')
102
+ end
103
+ if @elapsed_time_attribute
104
+ @logger.set_attribute(@elapsed_time_attribute, '%.6f' % (end_time_ - start_time_))
84
105
  end
85
106
  @logger.end_record
86
107
  end
@@ -51,29 +51,29 @@ module Sawmill
51
51
  #
52
52
  # Supported options include:
53
53
  #
54
- # <tt>:level_group</tt>::
54
+ # [<tt>:level_group</tt>]
55
55
  # Use a custom Sawmill::LevelGroup. Normally, you should leave this
56
56
  # set to the default, which is Sawmill::STANDARD_LEVELS.
57
- # <tt>:level</tt>::
57
+ # [<tt>:level</tt>]
58
58
  # Default level to use for log messages when no level is explicitly
59
59
  # provided. By default, this is set to the level group's default,
60
60
  # which in the case of the standard levels is :INFO.
61
- # <tt>:attribute_level</tt>::
61
+ # [<tt>:attribute_level</tt>]
62
62
  # Default level to use for attributes when no level is explicitly
63
63
  # provided. By default, this is set to the level group's highest,
64
64
  # level, which in the case of the standard levels is :ANY.
65
- # <tt>:progname</tt>::
65
+ # [<tt>:progname</tt>]
66
66
  # Progname to use in log messages. Default is "sawmill".
67
- # <tt>:record_progname</tt>::
67
+ # [<tt>:record_progname</tt>]
68
68
  # Progname to use in special log entries dealing with log records
69
69
  # (i.e. record delimiters and attribute messages). Default is the
70
70
  # same as the normal progname setting.
71
- # <tt>:record_id_generator</tt>::
71
+ # [<tt>:record_id_generator</tt>]
72
72
  # A proc that generates and returns a new record ID if one is not
73
73
  # explicitly passed into begin_record. If you do not provide a
74
74
  # generator, the default one is used, which generates an ID using the
75
75
  # variant 4 (random) UUID standard.
76
- # <tt>:processor</tt>::
76
+ # [<tt>:processor</tt>]
77
77
  # A processor for log entries generated by this logger.
78
78
  # If not specified, log entries are written out to STDOUT.
79
79
 
@@ -53,10 +53,10 @@ module Sawmill
53
53
  #
54
54
  # Recognized options include:
55
55
  #
56
- # <tt>:levels</tt>
56
+ # [<tt>:levels</tt>]
57
57
  # Sawmill::LevelGroup to use to parse log levels.
58
58
  # If not specified, Sawmill::STANDARD_LEVELS is used by default.
59
- # <tt>:emit_incomplete_records_at_eof</tt>
59
+ # [<tt>:emit_incomplete_records_at_eof</tt>]
60
60
  # If set to true, causes any incomplete log records to be emitted
61
61
  # in their incomplete state when EOF is reached on all streams.
62
62
 
@@ -61,19 +61,19 @@ module Sawmill
61
61
  #
62
62
  # Recognized options include:
63
63
  #
64
- # <tt>:levels</tt>
64
+ # [<tt>:levels</tt>]
65
65
  # Sawmill::LevelGroup to use to parse log levels.
66
66
  # If not specified, Sawmill::STANDARD_LEVELS is used by default.
67
- # <tt>:emit_incomplete_records_at_eof</tt>
67
+ # [<tt>:emit_incomplete_records_at_eof</tt>]
68
68
  # If set to true, causes any incomplete log records to be emitted
69
69
  # in their incomplete state when EOF is reached.
70
- # <tt>:encoding</tt>
70
+ # [<tt>:encoding</tt>]
71
71
  # Overrides the IO encoding. (Ruby 1.9 only). If specified, lines
72
72
  # read from the stream are assumed to be in this encoding. If not
73
73
  # specified, the IO's default encoding is honored.
74
74
  # Note that the encoding may also be modified by the stream itself,
75
75
  # if an appropriate parser directive is encountered.
76
- # <tt>:internal_encoding</tt>
76
+ # [<tt>:internal_encoding</tt>]
77
77
  # Transcodes strings as they are read. (Ruby 1.9 only). If specified,
78
78
  # lines are transcoded into this encoding after they are read from
79
79
  # the stream. If not specified, no post-transcoding is done.
@@ -80,6 +80,9 @@ module Sawmill
80
80
  @request_id_key = 'sawmill.request_id'
81
81
  @start_time_attribute = nil
82
82
  @end_time_attribute = nil
83
+ @elapsed_time_attribute = nil
84
+ @pre_logger = nil
85
+ @post_logger = nil
83
86
  end
84
87
 
85
88
  # The log file to write to. This should be either an IO object, or
@@ -116,6 +119,28 @@ module Sawmill
116
119
  attr_accessor :start_time_attribute
117
120
  # This option is passed to Sawmill::LogRecordMiddleware::new
118
121
  attr_accessor :end_time_attribute
122
+ # This option is passed to Sawmill::LogRecordMiddleware::new
123
+ attr_accessor :elapsed_time_attribute
124
+
125
+ def pre_logger(proc_=false, &block_)
126
+ if block_
127
+ @pre_logger = block_
128
+ elsif proc_ != false
129
+ @pre_logger = proc_
130
+ end
131
+ @pre_logger
132
+ end
133
+ attr_writer :pre_logger
134
+
135
+ def post_logger(proc_=false, &block_)
136
+ if block_
137
+ @post_logger = block_
138
+ elsif proc_ != false
139
+ @post_logger = proc_
140
+ end
141
+ @post_logger
142
+ end
143
+ attr_writer :post_logger
119
144
 
120
145
  end
121
146
 
@@ -143,7 +168,10 @@ module Sawmill
143
168
  ::Sawmill::LogRecordMiddleware, logger_,
144
169
  :request_id_key => myconfig_.request_id_key,
145
170
  :start_time_attribute => myconfig_.start_time_attribute,
146
- :end_time_attribute => myconfig_.end_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)
147
175
  end
148
176
 
149
177
 
@@ -50,14 +50,14 @@ module Sawmill
50
50
  #
51
51
  # Recognized options include:
52
52
  #
53
- # <tt>:postprocessor</tt>::
53
+ # [<tt>:postprocessor</tt>]
54
54
  # Postprocessor proc for individual reports.
55
- # <tt>:separator</tt>::
55
+ # [<tt>:separator</tt>]
56
56
  # Separator string for reports. Default is a single newline.
57
- # <tt>:header</tt>::
57
+ # [<tt>:header</tt>]
58
58
  # Header string for the final compiled report.
59
59
  # Default is the empty string.
60
- # <tt>:footer</tt>::
60
+ # [<tt>:footer</tt>]
61
61
  # Footer string for the final compiled report.
62
62
  # Default is the empty string.
63
63
 
@@ -48,7 +48,7 @@ module Sawmill
48
48
  #
49
49
  # Recognized options include:
50
50
  #
51
- # <tt>:label</tt>::
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}"
@@ -52,14 +52,14 @@ module Sawmill
52
52
  #
53
53
  # Recognized options include:
54
54
  #
55
- # <tt>:include_id</tt>::
55
+ # [<tt>:include_id</tt>]
56
56
  # Include the record ID in every log entry. Default is false.
57
- # <tt>:fractional_second_digits</tt>::
57
+ # [<tt>:fractional_second_digits</tt>]
58
58
  # Number of digits of fractional seconds to display in timestamps.
59
59
  # Default is 2. Accepted values are 0 to 6.
60
- # <tt>:level_width</tt>::
60
+ # [<tt>:level_width</tt>]
61
61
  # Column width of the level field.
62
- # <tt>:entry_length_limit</tt>::
62
+ # [<tt>:entry_length_limit</tt>]
63
63
  # Limit to the entry length. Entries are truncated to this length
64
64
  # when written. If not specified, entries are not truncated.
65
65
 
@@ -50,10 +50,10 @@ module Sawmill
50
50
  #
51
51
  # Recognized options include:
52
52
  #
53
- # <tt>:limit</tt>::
53
+ # [<tt>:limit</tt>]
54
54
  # Size limit for the queue. If not specified, the queue can grow
55
55
  # arbitrarily large.
56
- # <tt>:drop_oldest</tt>::
56
+ # [<tt>:drop_oldest</tt>]
57
57
  # If set to true, then when an item is added to a full queue, the
58
58
  # oldest item is dropped. If set to false or not specified, then
59
59
  # the new item is not added.
@@ -73,15 +73,15 @@ module Sawmill
73
73
  # set of options that will be used to instantiate the strategy.
74
74
  # In addition to those options, the following options are recognized:
75
75
  #
76
- # <tt>:omit_directives</tt>::
76
+ # [<tt>:omit_directives</tt>]
77
77
  # If true, omit standard logfile directives. Default is false.
78
- # <tt>:concurrent_writes</tt>::
78
+ # [<tt>:concurrent_writes</tt>]
79
79
  # Set this to true if you expect multiple processes to attempt to
80
80
  # write to the same log file simultaneously. This option causes the
81
81
  # rotater to surround writes with an acquisition of the cooperative
82
82
  # filesystem lock (if available) for the logfile, in an attempt to
83
83
  # prevent lines from interleaving in one another. Default is false.
84
- # <tt>:encoding</tt>::
84
+ # [<tt>:encoding</tt>]
85
85
  # Specify an encoding for file data. (Ruby 1.9 only).
86
86
  # You may pass either an encoding object or an encoding name.
87
87
  # If not specified, writes raw bytes (e.g. defaults to ASCII-8BIT).
@@ -110,7 +110,7 @@ module Sawmill
110
110
  #
111
111
  # The following options are recognized:
112
112
  #
113
- # <tt>:auto_rotate</tt>::
113
+ # [<tt>:auto_rotate</tt>]
114
114
  # Put the channel in auto-rotate mode. In this mode, the rotater is
115
115
  # allowed to rotate the logfile at any time for that channel. It is
116
116
  # the equivalent of calling check_rotate on the channel after every
@@ -61,29 +61,29 @@ module Sawmill
61
61
  #
62
62
  # Recognized options include:
63
63
  #
64
- # <tt>:turnover_frequency</tt>::
64
+ # [<tt>:turnover_frequency</tt>]
65
65
  # How often the log files should turn over. Allowed values are:
66
66
  # <tt>:yearly</tt>, <tt>:monthly</tt>, <tt>:daily</tt>,
67
67
  # <tt>:hourly</tt>, and <tt>:never</tt>.
68
- # <tt>:basedir</tt>::
68
+ # [<tt>:basedir</tt>]
69
69
  # The base directory used if the filepath is a relative path.
70
70
  # If not specified, the current working directory is used.
71
- # <tt>:path_prefix</tt>::
71
+ # [<tt>:path_prefix</tt>]
72
72
  # The logfile path prefix.
73
73
  # In the filename "rails.2009-10-11.log", the prefix is "rails".
74
74
  # If not specified, defaults to "sawmill".
75
- # <tt>:path_suffix</tt>::
75
+ # [<tt>:path_suffix</tt>]
76
76
  # The logfile name prefix.
77
77
  # In the filename "rails.2009-10-11.log", the suffix is ".log".
78
78
  # If not specified, defaults to ".log".
79
- # <tt>:uniquifier</tt>::
79
+ # [<tt>:uniquifier</tt>]
80
80
  # If provided, log files are never reopened. (That is, they are
81
81
  # opened with ::File::CREAT | ::File::EXCL.) The value of this
82
82
  # parameter must be a proc that returns an actual file name to
83
83
  # attempt to open. This proc is called repeatedly until it either
84
84
  # returns a file path that does not yet exist, or signals failure
85
85
  # by returning nil. See the session on Uniquifiers below.
86
- # <tt>:local_datestamps</tt>::
86
+ # [<tt>:local_datestamps</tt>]
87
87
  # If true, use the local timezone to create datestamps.
88
88
  # The default is to use UTC.
89
89
  #
@@ -111,17 +111,18 @@ module Sawmill
111
111
  # state it wishes to persist through the process. These keys are
112
112
  # given to the proc by DateBasedLogFile. Any other keys are
113
113
  # available for use by the proc.
114
- # <tt>:original_path</tt>::
114
+ #
115
+ # [<tt>:original_path</tt>]
115
116
  # The original file path generated by DateBasedLogFile, which
116
117
  # would have been used if there were no uniquifier.
117
- # <tt>:last_path</tt>::
118
+ # [<tt>:last_path</tt>]
118
119
  # The last path generated by the proc, or nil if this is the
119
120
  # first time this proc is called for a particular logfile.
120
- # <tt>:basedir</tt>::
121
+ # [<tt>:basedir</tt>]
121
122
  # The basedir of the DateBasedLogFile.
122
- # <tt>:path_prefix</tt>::
123
+ # [<tt>:path_prefix</tt>]
123
124
  # The path_prefix of the DateBasedLogFile.
124
- # <tt>:path_suffix</tt>::
125
+ # [<tt>:path_suffix</tt>]
125
126
  # The path_suffix of the DateBasedLogFile.
126
127
 
127
128
  def initialize(options_)
@@ -209,7 +210,7 @@ module Sawmill
209
210
  #
210
211
  # The following options are available:
211
212
  #
212
- # <tt>:min_digits</tt>::
213
+ # [<tt>:min_digits</tt>]
213
214
  # If provided, indicates the minimum number of digits for the
214
215
  # unique number. For example, if :digits is set to 2, these
215
216
  # names are generated:
@@ -226,7 +227,7 @@ module Sawmill
226
227
  # rails.2009-10-11.101.log
227
228
  # etc.
228
229
  # The default is 1.
229
- # <tt>:start_value</tt>::
230
+ # [<tt>:start_value</tt>]
230
231
  # The first value for the unique number. Default is 0.
231
232
 
232
233
  def simple_uniquifier(opts_={})
@@ -56,23 +56,23 @@ module Sawmill
56
56
  #
57
57
  # Recognized options include:
58
58
  #
59
- # <tt>:basedir</tt>::
59
+ # [<tt>:basedir</tt>]
60
60
  # The base directory used if the filepath is a relative path.
61
61
  # If not specified, the current working directory is used.
62
- # <tt>:file_path</tt>::
62
+ # [<tt>:file_path</tt>]
63
63
  # The path to the log file. This may be an absolute path or a
64
64
  # path relative to basedir.
65
65
  # If not specified, defaults to "sawmill.log".
66
- # <tt>:max_file_size</tt>::
66
+ # [<tt>:max_file_size</tt>]
67
67
  # A logfile will try to rotate once it has reached this size in
68
68
  # bytes. If not specified, the file size is not checked.
69
- # <tt>:shift_period</tt>::
69
+ # [<tt>:shift_period</tt>]
70
70
  # A logfile will try to rotate once it has been in service for
71
71
  # this many seconds. This parameter also recognizes the values
72
72
  # <tt>:yearly</tt>, <tt>:monthly</tt>, <tt>:daily</tt>,
73
73
  # and <tt>:hourly</tt>. If not specified, the file's age is
74
74
  # not checked.
75
- # <tt>:history_size</tt>::
75
+ # [<tt>:history_size</tt>]
76
76
  # The maximum number of old logfiles (files with indexes) to
77
77
  # keep. Files beyond this history size will be automatically
78
78
  # deleted. Default is 1. This value must be at least 1.
@@ -46,10 +46,10 @@ module Sawmill
46
46
 
47
47
  # Recognized options include:
48
48
  #
49
- # <tt>:limit</tt>::
49
+ # [<tt>:limit</tt>]
50
50
  # Size limit for the queue. If not specified, the queue can grow
51
51
  # arbitrarily large.
52
- # <tt>:drop_oldest</tt>::
52
+ # [<tt>:drop_oldest</tt>]
53
53
  # If set to true, then when an item is added to a full queue, the
54
54
  # oldest item is dropped. If set to false or not specified, then
55
55
  # the new item is not added.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,47 +1,36 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sawmill
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 12
9
- version: 0.1.12
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.13
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Daniel Azuma
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-11-01 00:00:00 -07:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-07-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: blockenspiel
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2153258020 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- - 4
31
- - 1
32
- version: 0.4.1
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.3
33
22
  type: :runtime
34
- version_requirements: *id001
35
- description: Sawmill is a logging and log analysis system for Ruby. It extends the basic Ruby logging facility with log records and parsing abilities.
23
+ prerelease: false
24
+ version_requirements: *2153258020
25
+ description: Sawmill is a logging and log analysis system for Ruby. It extends the
26
+ basic Ruby logging facility with log records and parsing abilities.
36
27
  email: dazuma@gmail.com
37
28
  executables: []
38
-
39
29
  extensions: []
40
-
41
- extra_rdoc_files:
30
+ extra_rdoc_files:
42
31
  - History.rdoc
43
32
  - README.rdoc
44
- files:
33
+ files:
45
34
  - lib/sawmill/entry.rb
46
35
  - lib/sawmill/entry_classifier.rb
47
36
  - lib/sawmill/entry_processor/build_records.rb
@@ -81,57 +70,47 @@ files:
81
70
  - lib/sawmill/util/queue.rb
82
71
  - lib/sawmill/version.rb
83
72
  - lib/sawmill.rb
73
+ - test/tc_entry_processors.rb
74
+ - test/tc_formatter_parser.rb
75
+ - test/tc_levels.rb
76
+ - test/tc_logger.rb
77
+ - test/tc_multi_parser.rb
78
+ - test/tc_record_processors.rb
79
+ - test/tc_records.rb
80
+ - test/tc_reports.rb
84
81
  - History.rdoc
85
82
  - README.rdoc
86
- - tests/tc_entry_processors.rb
87
- - tests/tc_formatter_parser.rb
88
- - tests/tc_levels.rb
89
- - tests/tc_logger.rb
90
- - tests/tc_multi_parser.rb
91
- - tests/tc_record_processors.rb
92
- - tests/tc_records.rb
93
- - tests/tc_reports.rb
94
83
  - Version
95
- has_rdoc: true
96
84
  homepage: http://virtuoso.rubyforge.org/sawmill
97
85
  licenses: []
98
-
99
86
  post_install_message:
100
87
  rdoc_options: []
101
-
102
- require_paths:
88
+ require_paths:
103
89
  - lib
104
- required_ruby_version: !ruby/object:Gem::Requirement
90
+ required_ruby_version: !ruby/object:Gem::Requirement
105
91
  none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- segments:
110
- - 1
111
- - 8
112
- - 7
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
113
95
  version: 1.8.7
114
- required_rubygems_version: !ruby/object:Gem::Requirement
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
97
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- segments:
120
- - 0
121
- version: "0"
98
+ requirements:
99
+ - - ! '>'
100
+ - !ruby/object:Gem::Version
101
+ version: 1.3.1
122
102
  requirements: []
123
-
124
103
  rubyforge_project: virtuoso
125
- rubygems_version: 1.3.7
104
+ rubygems_version: 1.8.5
126
105
  signing_key:
127
106
  specification_version: 3
128
107
  summary: Sawmill is a logging and log analysis system for Ruby.
129
- test_files:
130
- - tests/tc_entry_processors.rb
131
- - tests/tc_formatter_parser.rb
132
- - tests/tc_levels.rb
133
- - tests/tc_logger.rb
134
- - tests/tc_multi_parser.rb
135
- - tests/tc_record_processors.rb
136
- - tests/tc_records.rb
137
- - tests/tc_reports.rb
108
+ test_files:
109
+ - test/tc_entry_processors.rb
110
+ - test/tc_formatter_parser.rb
111
+ - test/tc_levels.rb
112
+ - test/tc_logger.rb
113
+ - test/tc_multi_parser.rb
114
+ - test/tc_record_processors.rb
115
+ - test/tc_records.rb
116
+ - test/tc_reports.rb