jls-grok 0.9.2 → 0.9.4
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/grok-pure.rb +27 -7
- metadata +6 -6
data/lib/grok-pure.rb
CHANGED
@@ -48,15 +48,19 @@ class Grok
|
|
48
48
|
@logger.info("Adding pattern", name => pattern)
|
49
49
|
@patterns[name] = pattern
|
50
50
|
return nil
|
51
|
-
end
|
51
|
+
end # def add_pattern
|
52
52
|
|
53
53
|
public
|
54
54
|
def add_patterns_from_file(path)
|
55
55
|
file = File.new(path, "r")
|
56
56
|
file.each do |line|
|
57
|
-
|
57
|
+
# Skip comments
|
58
|
+
next if line =~ /^\s*#/
|
59
|
+
# File format is: NAME ' '+ PATTERN '\n'
|
58
60
|
name, pattern = line.gsub(/^\s*/, "").split(/\s+/, 2)
|
61
|
+
# If the line is malformed, skip it.
|
59
62
|
next if pattern.nil?
|
63
|
+
# Trim newline and add the pattern.
|
60
64
|
add_pattern(name, pattern.chomp)
|
61
65
|
end
|
62
66
|
return nil
|
@@ -66,7 +70,7 @@ class Grok
|
|
66
70
|
def compile(pattern)
|
67
71
|
@capture_map = {}
|
68
72
|
|
69
|
-
iterations_left =
|
73
|
+
iterations_left = 1000
|
70
74
|
@pattern = pattern
|
71
75
|
@expanded_pattern = pattern
|
72
76
|
index = 0
|
@@ -88,18 +92,34 @@ class Grok
|
|
88
92
|
# create a named capture index that we can push later as the named
|
89
93
|
# pattern. We do this because ruby regexp can't capture something
|
90
94
|
# by the same name twice.
|
91
|
-
|
95
|
+
regex = @patterns[m["pattern"]]
|
96
|
+
#puts "patterns[#{m["pattern"]}] => #{regex}"
|
92
97
|
|
93
98
|
capture = "a#{index}" # named captures have to start with letters?
|
94
99
|
#capture = "%04d" % "#{index}" # named captures have to start with letters?
|
95
|
-
replacement_pattern = "(?<#{capture}>#{
|
96
|
-
#p(:input => m[0], :pattern => replacement_pattern)
|
100
|
+
replacement_pattern = "(?<#{capture}>#{regex})"
|
97
101
|
@capture_map[capture] = m["name"]
|
98
|
-
|
102
|
+
|
103
|
+
#puts "Before: #{@expanded_pattern}"
|
104
|
+
#puts "m[0]: #{m[0]}"
|
105
|
+
#puts "replacement_pattern => #{replacement_pattern}"
|
106
|
+
#puts "Proposed: #{@expanded_pattern.sub(m[0], replacement_pattern)}"
|
107
|
+
|
108
|
+
# Ruby's String#sub() has a bug (or misfeature) that causes it to do bad
|
109
|
+
# things to backslashes in string replacements, so let's work around it
|
110
|
+
# See this gist for more details: https://gist.github.com/1491437
|
111
|
+
# This hack should resolve LOGSTASH-226.
|
112
|
+
@expanded_pattern.sub!(m[0]) { |s| replacement_pattern }
|
113
|
+
|
114
|
+
#puts "After: #{@expanded_pattern}"
|
115
|
+
#puts "m[0]: #{m[0]}"
|
116
|
+
#puts "replacement_pattern => #{replacement_pattern}"
|
99
117
|
index += 1
|
100
118
|
end
|
101
119
|
end
|
102
120
|
|
121
|
+
#@logger.debug("Finished expanding", :string => @expanded_pattern)
|
122
|
+
#puts "Expanded: #{@expanded_pattern}"
|
103
123
|
@regexp = Regexp.new(@expanded_pattern)
|
104
124
|
@logger.debug("Grok compiled OK", :pattern => pattern,
|
105
125
|
:expanded_pattern => @expanded_pattern)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jls-grok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,19 +10,19 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-12-17 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: cabin
|
17
|
-
requirement: &
|
17
|
+
requirement: &7424980 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - =
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 0.1.7
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *7424980
|
26
26
|
description: Grok ruby bindings - pattern match/extraction tool
|
27
27
|
email:
|
28
28
|
- jls@semicomplete.com
|