sawmill 0.1.15 → 0.1.16
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +7 -0
- data/Version +1 -1
- data/lib/sawmill.rb +6 -6
- data/lib/sawmill/entry.rb +108 -108
- data/lib/sawmill/entry_classifier.rb +19 -19
- data/lib/sawmill/entry_processor.rb +63 -63
- data/lib/sawmill/entry_processor/build_records.rb +39 -39
- data/lib/sawmill/entry_processor/compile_report.rb +32 -32
- data/lib/sawmill/entry_processor/conditionals.rb +110 -110
- data/lib/sawmill/entry_processor/count_entries.rb +27 -27
- data/lib/sawmill/entry_processor/filter_by_basic_fields.rb +32 -32
- data/lib/sawmill/entry_processor/filter_by_block.rb +28 -28
- data/lib/sawmill/entry_processor/format.rb +41 -36
- data/lib/sawmill/entry_processor/interpret_stats.rb +24 -24
- data/lib/sawmill/entry_processor/simple_queue.rb +38 -38
- data/lib/sawmill/errors.rb +28 -28
- data/lib/sawmill/interface.rb +51 -51
- data/lib/sawmill/level.rb +75 -75
- data/lib/sawmill/log_record_middleware.rb +21 -21
- data/lib/sawmill/logger.rb +94 -94
- data/lib/sawmill/multi_parser.rb +28 -28
- data/lib/sawmill/parser.rb +32 -32
- data/lib/sawmill/railtie.rb +31 -31
- data/lib/sawmill/record.rb +74 -74
- data/lib/sawmill/record_processor.rb +54 -54
- data/lib/sawmill/record_processor/compile_report.rb +32 -32
- data/lib/sawmill/record_processor/conditionals.rb +92 -92
- data/lib/sawmill/record_processor/count_records.rb +24 -24
- data/lib/sawmill/record_processor/decompose.rb +21 -21
- data/lib/sawmill/record_processor/filter_by_attributes.rb +22 -22
- data/lib/sawmill/record_processor/filter_by_block.rb +29 -29
- data/lib/sawmill/record_processor/filter_by_record_id.rb +22 -22
- data/lib/sawmill/record_processor/format.rb +24 -24
- data/lib/sawmill/record_processor/simple_queue.rb +44 -44
- data/lib/sawmill/rotater.rb +60 -60
- data/lib/sawmill/rotater/base.rb +28 -28
- data/lib/sawmill/rotater/date_based_log_file.rb +50 -50
- data/lib/sawmill/rotater/shifting_log_file.rb +34 -34
- data/lib/sawmill/stats_middleware.rb +21 -21
- data/lib/sawmill/stats_railtie.rb +33 -33
- data/lib/sawmill/util/heap.rb +41 -41
- data/lib/sawmill/util/processor_tools.rb +17 -17
- data/lib/sawmill/util/queue.rb +33 -33
- data/lib/sawmill/version.rb +9 -9
- data/test/tc_entry_processors.rb +27 -27
- data/test/tc_formatter_parser.rb +40 -40
- data/test/tc_levels.rb +27 -27
- data/test/tc_logger.rb +49 -49
- data/test/tc_multi_parser.rb +18 -18
- data/test/tc_record_processors.rb +21 -21
- data/test/tc_records.rb +39 -39
- data/test/tc_reports.rb +19 -19
- metadata +10 -5
data/lib/sawmill/rotater/base.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Sawmill formatter 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,56 +35,56 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module Sawmill
|
38
|
-
|
38
|
+
|
39
39
|
class Rotater
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# This class defines the rotation strategy contract. Classes that
|
43
43
|
# implement rotation strategies need not subclass this base class, but
|
44
44
|
# must implement the methods defined here.
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# This base class itself merely writes to STDOUT and does not do
|
47
47
|
# any rotation.
|
48
|
-
|
48
|
+
|
49
49
|
class Base
|
50
|
-
|
51
|
-
|
50
|
+
|
51
|
+
|
52
52
|
# Return the currently preferred handle, identifying which io stream
|
53
53
|
# should be written to preferentially unless a channel is constrained
|
54
54
|
# to use an earlier stream.
|
55
|
-
|
55
|
+
|
56
56
|
def preferred_handle
|
57
57
|
0
|
58
58
|
end
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
|
61
61
|
# Open and return an IO object for the given handle.
|
62
62
|
# This is guaranteed not to be called twice unless the stream has been
|
63
63
|
# closed in the meantime.
|
64
|
-
|
64
|
+
|
65
65
|
def open_handle(handle_)
|
66
66
|
::STDOUT
|
67
67
|
end
|
68
|
-
|
69
|
-
|
68
|
+
|
69
|
+
|
70
70
|
# Close the IO object for the given handle.
|
71
71
|
# This is guaranteed not be called unless the stream has been opened.
|
72
|
-
|
72
|
+
|
73
73
|
def close_handle(handle_, io_)
|
74
74
|
end
|
75
|
-
|
76
|
-
|
75
|
+
|
76
|
+
|
77
77
|
# This is a hook that is called before every write request to any
|
78
78
|
# stream managed by this rotater. You may optionally perform any
|
79
79
|
# periodic tasks here, such as renaming log files.
|
80
|
-
|
80
|
+
|
81
81
|
def before_write
|
82
82
|
end
|
83
|
-
|
84
|
-
|
83
|
+
|
84
|
+
|
85
85
|
end
|
86
|
-
|
87
|
-
|
86
|
+
|
87
|
+
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Sawmill formatter 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,35 +35,35 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module Sawmill
|
38
|
-
|
38
|
+
|
39
39
|
class Rotater
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# A rotation strategy that produces log files with the date stamp in the
|
43
43
|
# file name. For example, you could set up an hourly log rotation that
|
44
44
|
# produces the following files:
|
45
|
-
#
|
45
|
+
#
|
46
46
|
# rails.2009-10-09-22.log
|
47
47
|
# rails.2009-10-09-23.log
|
48
48
|
# rails.2009-10-10-00.log
|
49
49
|
# rails.2009-10-10-01.log
|
50
50
|
# etc...
|
51
|
-
#
|
51
|
+
#
|
52
52
|
# The exact format depends on the rotation frequency, which could be
|
53
53
|
# anywhere from yearly to hourly. For settings less frequent than
|
54
54
|
# hourly, fewer fields will appear in the date stamp portion of the
|
55
55
|
# file name.
|
56
|
-
|
56
|
+
|
57
57
|
class DateBasedLogFile
|
58
|
-
|
59
|
-
|
58
|
+
|
59
|
+
|
60
60
|
# Create a new date-based log file rotation strategy.
|
61
|
-
#
|
61
|
+
#
|
62
62
|
# Recognized options include:
|
63
|
-
#
|
63
|
+
#
|
64
64
|
# [<tt>:turnover_frequency</tt>]
|
65
65
|
# How often the log files should turn over. Allowed values are:
|
66
|
-
# <tt>:yearly</tt>, <tt>:monthly</tt>, <tt>:daily</tt>,
|
66
|
+
# <tt>:yearly</tt>, <tt>:monthly</tt>, <tt>:daily</tt>,
|
67
67
|
# <tt>:hourly</tt>, and <tt>:never</tt>.
|
68
68
|
# [<tt>:basedir</tt>]
|
69
69
|
# The base directory used if the filepath is a relative path.
|
@@ -86,16 +86,16 @@ module Sawmill
|
|
86
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
|
+
#
|
90
90
|
# === Uniquifiers
|
91
|
-
#
|
91
|
+
#
|
92
92
|
# DateBasedLogFile provides a facility for ensuring that log files
|
93
93
|
# are written to by only one process, by generating unique file
|
94
94
|
# names for log files. This facility is useful, for example, if you
|
95
95
|
# are deploying via Phusion Passenger where you may have a variable
|
96
96
|
# number of rails processes, and you want each process to own its
|
97
97
|
# own logfile so entries in log records are not interleaved.
|
98
|
-
#
|
98
|
+
#
|
99
99
|
# To activate this feature, pass a proc to the <tt>:uniquifier</tt>
|
100
100
|
# option. When DateBasedLogFile wants to open a log file for
|
101
101
|
# writing, it first calls this proc. The proc should return a file
|
@@ -105,13 +105,13 @@ module Sawmill
|
|
105
105
|
# the file already exists, the proc will be called again, and
|
106
106
|
# repeatedly until it either returns a path that has not yet been
|
107
107
|
# created, or nil indicating that it has given up.
|
108
|
-
#
|
108
|
+
#
|
109
109
|
# The proc is passed a single hash that provides information about
|
110
110
|
# what path to generate, as well as space for the proc to store any
|
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
|
-
#
|
114
|
+
#
|
115
115
|
# [<tt>:original_path</tt>]
|
116
116
|
# The original file path generated by DateBasedLogFile, which
|
117
117
|
# would have been used if there were no uniquifier.
|
@@ -124,7 +124,7 @@ module Sawmill
|
|
124
124
|
# The path_prefix of the DateBasedLogFile.
|
125
125
|
# [<tt>:path_suffix</tt>]
|
126
126
|
# The path_suffix of the DateBasedLogFile.
|
127
|
-
|
127
|
+
|
128
128
|
def initialize(options_)
|
129
129
|
@turnover_frequency = options_[:turnover_frequency] || :none
|
130
130
|
@basedir = options_[:basedir] || options_[:dirname] || ::Dir.getwd
|
@@ -142,10 +142,10 @@ module Sawmill
|
|
142
142
|
else nil
|
143
143
|
end
|
144
144
|
end
|
145
|
-
|
146
|
-
|
145
|
+
|
146
|
+
|
147
147
|
# Implements the rotation strategy contract.
|
148
|
-
|
148
|
+
|
149
149
|
def preferred_handle
|
150
150
|
if @date_pattern
|
151
151
|
time_ = ::Time.now
|
@@ -155,10 +155,10 @@ module Sawmill
|
|
155
155
|
''
|
156
156
|
end
|
157
157
|
end
|
158
|
-
|
159
|
-
|
158
|
+
|
159
|
+
|
160
160
|
# Implements the rotation strategy contract.
|
161
|
-
|
161
|
+
|
162
162
|
def open_handle(handle_)
|
163
163
|
path_ = ::File.expand_path(@date_pattern ? "#{@prefix}.#{handle_}#{@suffix}" : @prefix+@suffix, @basedir)
|
164
164
|
file_ = nil
|
@@ -181,35 +181,35 @@ module Sawmill
|
|
181
181
|
file_.sync = true
|
182
182
|
file_
|
183
183
|
end
|
184
|
-
|
185
|
-
|
184
|
+
|
185
|
+
|
186
186
|
# Implements the rotation strategy contract.
|
187
|
-
|
187
|
+
|
188
188
|
def close_handle(handle_, io_)
|
189
189
|
io_.close
|
190
190
|
end
|
191
|
-
|
192
|
-
|
191
|
+
|
192
|
+
|
193
193
|
# Implements the rotation strategy contract.
|
194
|
-
|
194
|
+
|
195
195
|
def before_write
|
196
196
|
end
|
197
|
-
|
198
|
-
|
197
|
+
|
198
|
+
|
199
199
|
class << self
|
200
|
-
|
201
|
-
|
200
|
+
|
201
|
+
|
202
202
|
# Returns a simple uniquifier that inserts an incrementing number
|
203
203
|
# before the path suffix. i.e. if the non-uniquified filename is
|
204
204
|
# "rails.2009-10-11.log", then these names are generated:
|
205
|
-
#
|
205
|
+
#
|
206
206
|
# rails.2009-10-11.0.log
|
207
207
|
# rails.2009-10-11.1.log
|
208
208
|
# rails.2009-10-11.2.log
|
209
209
|
# etc.
|
210
|
-
#
|
210
|
+
#
|
211
211
|
# The following options are available:
|
212
|
-
#
|
212
|
+
#
|
213
213
|
# [<tt>:min_digits</tt>]
|
214
214
|
# If provided, indicates the minimum number of digits for the
|
215
215
|
# unique number. For example, if :digits is set to 2, these
|
@@ -229,7 +229,7 @@ module Sawmill
|
|
229
229
|
# The default is 1.
|
230
230
|
# [<tt>:start_value</tt>]
|
231
231
|
# The first value for the unique number. Default is 0.
|
232
|
-
|
232
|
+
|
233
233
|
def simple_uniquifier(opts_={})
|
234
234
|
if (digits_ = opts_[:min_digits])
|
235
235
|
pattern_ = "%s.%0#{digits_.to_i}d%s"
|
@@ -257,14 +257,14 @@ module Sawmill
|
|
257
257
|
pattern_ % [hash_[:pre], hash_[:value], hash_[:post]]
|
258
258
|
end
|
259
259
|
end
|
260
|
-
|
261
|
-
|
260
|
+
|
261
|
+
|
262
262
|
end
|
263
|
-
|
264
|
-
|
263
|
+
|
264
|
+
|
265
265
|
end
|
266
|
-
|
267
|
-
|
266
|
+
|
267
|
+
|
268
268
|
end
|
269
|
-
|
269
|
+
|
270
270
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# -----------------------------------------------------------------------------
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Sawmill formatter 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,10 +35,10 @@
|
|
35
35
|
|
36
36
|
|
37
37
|
module Sawmill
|
38
|
-
|
38
|
+
|
39
39
|
class Rotater
|
40
|
-
|
41
|
-
|
40
|
+
|
41
|
+
|
42
42
|
# A rotation strategy that "shifts" log files by appending index numbers
|
43
43
|
# to the filename when the file reaches a certain size or age. So when
|
44
44
|
# the file "foo.log" is ready to rotate, it is renamed "foo.log.0", and
|
@@ -48,14 +48,14 @@ module Sawmill
|
|
48
48
|
# logfile is always the one with the largest number suffix, and the
|
49
49
|
# file currently being written to has no suffix.
|
50
50
|
# This is a common rotation strategy for many unix tools.
|
51
|
-
|
51
|
+
|
52
52
|
class ShiftingLogFile
|
53
|
-
|
54
|
-
|
53
|
+
|
54
|
+
|
55
55
|
# Create a new shifting log file rotation strategy.
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# Recognized options include:
|
58
|
-
#
|
58
|
+
#
|
59
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.
|
@@ -69,14 +69,14 @@ module Sawmill
|
|
69
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
|
-
# <tt>:yearly</tt>, <tt>:monthly</tt>, <tt>:daily</tt>,
|
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
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.
|
79
|
-
|
79
|
+
|
80
80
|
def initialize(options_)
|
81
81
|
@max_logfile_size = options_[:max_file_size] || options_[:max_logfile_size]
|
82
82
|
@shift_period = options_[:shift_period]
|
@@ -92,23 +92,23 @@ module Sawmill
|
|
92
92
|
end
|
93
93
|
@history_size = options_[:history_size].to_i
|
94
94
|
@history_size = 1 if @history_size < 1 && (@max_logfile_size || @shift_period)
|
95
|
-
@normal_path = ::File.expand_path(options_[:file_path] || options_[:filepath] || 'sawmill.log',
|
95
|
+
@normal_path = ::File.expand_path(options_[:file_path] || options_[:filepath] || 'sawmill.log',
|
96
96
|
options_[:basedir] || ::Dir.getwd)
|
97
97
|
@preferred_handle = 0
|
98
98
|
@open_handles = {}
|
99
99
|
@last_shift = ::Time.now
|
100
100
|
end
|
101
|
-
|
102
|
-
|
101
|
+
|
102
|
+
|
103
103
|
# Implements the rotation strategy contract.
|
104
|
-
|
104
|
+
|
105
105
|
def preferred_handle
|
106
106
|
@preferred_handle
|
107
107
|
end
|
108
|
-
|
109
|
-
|
108
|
+
|
109
|
+
|
110
110
|
# Implements the rotation strategy contract.
|
111
|
-
|
111
|
+
|
112
112
|
def open_handle(handle_)
|
113
113
|
if handle_ == @preferred_handle
|
114
114
|
path_ = @normal_path
|
@@ -120,10 +120,10 @@ module Sawmill
|
|
120
120
|
@open_handles[handle_] = true
|
121
121
|
file_
|
122
122
|
end
|
123
|
-
|
124
|
-
|
123
|
+
|
124
|
+
|
125
125
|
# Implements the rotation strategy contract.
|
126
|
-
|
126
|
+
|
127
127
|
def close_handle(handle_, io_)
|
128
128
|
io_.close
|
129
129
|
if @preferred_handle - handle_ > @history_size
|
@@ -132,10 +132,10 @@ module Sawmill
|
|
132
132
|
@open_handles.delete(handle_)
|
133
133
|
nil
|
134
134
|
end
|
135
|
-
|
136
|
-
|
135
|
+
|
136
|
+
|
137
137
|
# Implements the rotation strategy contract.
|
138
|
-
|
138
|
+
|
139
139
|
def before_write
|
140
140
|
return unless @max_logfile_size || @shift_period
|
141
141
|
turnover_ = false
|
@@ -157,11 +157,11 @@ module Sawmill
|
|
157
157
|
@last_shift = ::Time.now
|
158
158
|
end
|
159
159
|
end
|
160
|
-
|
161
|
-
|
160
|
+
|
161
|
+
|
162
162
|
end
|
163
|
-
|
164
|
-
|
163
|
+
|
164
|
+
|
165
165
|
end
|
166
|
-
|
166
|
+
|
167
167
|
end
|