From a592c6fa1a4fd196425bb3d56344268b80f84aa1 Mon Sep 17 00:00:00 2001 From: Jordan Sissel Date: Mon, 21 Sep 2009 06:35:50 +0000 Subject: [PATCH] - Don't use GrokMatch#captures anymore, use GrokMatch#each_capture, as it is more efficient. With this new method, we only iterate over the captures once. --- lib/log/text.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/log/text.rb b/lib/log/text.rb index 61ec45093..ae5f5b738 100644 --- a/lib/log/text.rb +++ b/lib/log/text.rb @@ -53,20 +53,17 @@ module LogStash break if match end return nil unless match - res = match.captures + res = Hash.new { |h,k| h[k] = Array.new } # We're parsing GROK captures, and there are two kinds of outputs: # QUOTEDSTRING:bar - matched pattern QUOTEDSTRING, var named bar, keep # DATA - matched pattern DATA, but no variable name, so we ditch it - res.keys.each do |key| + match.each_capture do |key, value| if key =~ /^.+:(.+)$/ - if res[key].length == 1 - res[$1] = res[key][0] - else - res[$1] = res[key] - end + res[$1] = value + else + res[key] = value end - res.delete(key) end # add meta @LINE to represent the original input