apachecrunch 0.2 → 0.3
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/lib/log_element.rb +60 -6
- metadata +3 -3
data/lib/log_element.rb
CHANGED
@@ -52,12 +52,12 @@ class LogFormatElement
|
|
52
52
|
@regex = self.class.regex
|
53
53
|
end
|
54
54
|
|
55
|
-
# Casts a string found in the log to the correct type, using the class's
|
55
|
+
# Casts a string found in the log to the correct type, using the class's @_caster attribute.
|
56
56
|
def cast(string_value)
|
57
|
-
if
|
57
|
+
if _caster.nil?
|
58
58
|
return string_value
|
59
59
|
else
|
60
|
-
return
|
60
|
+
return _caster.cast(string_value)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -102,6 +102,60 @@ class TimeElement < LogFormatElement
|
|
102
102
|
@abbrev = "%t"
|
103
103
|
@name = :time
|
104
104
|
@regex = %q!\[\d\d/[A-Za-z]{3}/\d\d\d\d:\d\d:\d\d:\d\d [-+]\d\d\d\d\]!
|
105
|
+
|
106
|
+
@_derivation_regex = nil
|
107
|
+
@_month_map = {"Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6,
|
108
|
+
"Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12}
|
109
|
+
|
110
|
+
def self.derive(name, our_own_value)
|
111
|
+
if @_derivation_regex.nil?
|
112
|
+
@_derivation_regex = Regexp.compile(%q!^\[(\d\d)/([A-Za-z]{3})/(\d\d\d\d):(\d\d):(\d\d):(\d\d)!)
|
113
|
+
end
|
114
|
+
|
115
|
+
hsh = {}
|
116
|
+
if our_own_value =~ @_derivation_regex
|
117
|
+
hsh[:year] = $3.to_i
|
118
|
+
hsh[:month] = @_month_map[$2]
|
119
|
+
hsh[:day] = $1.to_i
|
120
|
+
|
121
|
+
hsh[:hour] = $4.to_i
|
122
|
+
hsh[:minute] = $5.to_i
|
123
|
+
hsh[:second] = $6.to_i
|
124
|
+
end
|
125
|
+
|
126
|
+
hsh[name]
|
127
|
+
end
|
128
|
+
|
129
|
+
def derived_elements
|
130
|
+
[YearElement, MonthElement, DayElement, HourElement, MinuteElement, SecondElement]
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
# Elements derived from TimeElement
|
136
|
+
class YearElement < LogFormatElement
|
137
|
+
@name = :year
|
138
|
+
@regex = %q!\d{4}!
|
139
|
+
end
|
140
|
+
class MonthElement < LogFormatElement
|
141
|
+
@name = :month
|
142
|
+
@regex = %q![A-Za-z]{3}!
|
143
|
+
end
|
144
|
+
class DayElement < LogFormatElement
|
145
|
+
@name = :day
|
146
|
+
@regex = %q!\d{2}!
|
147
|
+
end
|
148
|
+
class HourElement < LogFormatElement
|
149
|
+
@name = :hour
|
150
|
+
@regex = %q!\d{2}!
|
151
|
+
end
|
152
|
+
class MinuteElement < LogFormatElement
|
153
|
+
@name = :minute
|
154
|
+
@regex = %q!\d{2}!
|
155
|
+
end
|
156
|
+
class SecondElement < LogFormatElement
|
157
|
+
@name = :second
|
158
|
+
@regex = %q!\d{2}!
|
105
159
|
end
|
106
160
|
|
107
161
|
|
@@ -155,7 +209,7 @@ class BytesSentElement < LogFormatElement
|
|
155
209
|
@name = :bytes_sent
|
156
210
|
@regex = %q![\d-]+!
|
157
211
|
|
158
|
-
|
212
|
+
@_caster = CLFIntegerCast
|
159
213
|
end
|
160
214
|
|
161
215
|
|
@@ -164,7 +218,7 @@ class BytesSentWithHeadersElement < LogFormatElement
|
|
164
218
|
@name = :bytes_sent_with_headers
|
165
219
|
@regex = %q!\d+!
|
166
220
|
|
167
|
-
|
221
|
+
@_caster = IntegerCast
|
168
222
|
end
|
169
223
|
|
170
224
|
|
@@ -173,7 +227,7 @@ class ServeTimeMicroElement < LogFormatElement
|
|
173
227
|
@name = :serve_time_micro
|
174
228
|
@regex = %q!\d+!
|
175
229
|
|
176
|
-
|
230
|
+
@_caster = IntegerCast
|
177
231
|
end
|
178
232
|
|
179
233
|
|
metadata
CHANGED