jls-grok 0.9.0 → 0.9.1
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 +11 -4
- data/lib/grok/pure/pile.rb +14 -0
- metadata +44 -44
data/lib/grok-pure.rb
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
require "rubygems"
|
|
2
|
+
require "logger"
|
|
3
|
+
require "cabin"
|
|
2
4
|
|
|
3
5
|
# TODO(sissel): Check if 'grok' c-ext has been loaded and abort?
|
|
4
6
|
class Grok
|
|
5
7
|
attr_accessor :pattern
|
|
6
8
|
attr_accessor :expanded_pattern
|
|
9
|
+
attr_accessor :logger
|
|
7
10
|
|
|
8
11
|
PATTERN_RE = \
|
|
9
|
-
|
|
12
|
+
/%\{ # match '%{' not prefixed with '\'
|
|
10
13
|
(?<name> # match the pattern name
|
|
11
14
|
(?<pattern>[A-z0-9]+)
|
|
12
15
|
(?::(?<subname>[A-z0-9_:]+))?
|
|
@@ -19,7 +22,7 @@ class Grok
|
|
|
19
22
|
)+
|
|
20
23
|
))?
|
|
21
24
|
[^}]*
|
|
22
|
-
}/x
|
|
25
|
+
\}/x
|
|
23
26
|
|
|
24
27
|
GROK_OK = 0
|
|
25
28
|
GROK_ERROR_FILE_NOT_ACCESSIBLE = 1
|
|
@@ -33,13 +36,15 @@ class Grok
|
|
|
33
36
|
public
|
|
34
37
|
def initialize
|
|
35
38
|
@patterns = {}
|
|
39
|
+
@logger = Cabin::Channel.new
|
|
40
|
+
@logger.subscribe(Logger.new(STDOUT))
|
|
36
41
|
|
|
37
42
|
# TODO(sissel): Throw exception if we aren't using Ruby 1.9.2 or newer.
|
|
38
43
|
end # def initialize
|
|
39
44
|
|
|
40
45
|
public
|
|
41
46
|
def add_pattern(name, pattern)
|
|
42
|
-
|
|
47
|
+
@logger.info("Adding pattern", name => pattern)
|
|
43
48
|
@patterns[name] = pattern
|
|
44
49
|
return nil
|
|
45
50
|
end
|
|
@@ -49,7 +54,6 @@ class Grok
|
|
|
49
54
|
file = File.new(path, "r")
|
|
50
55
|
file.each do |line|
|
|
51
56
|
next if line =~ /^\s*#/
|
|
52
|
-
#puts "Pattern: #{line}"
|
|
53
57
|
name, pattern = line.gsub(/^\s*/, "").split(/\s+/, 2)
|
|
54
58
|
next if pattern.nil?
|
|
55
59
|
add_pattern(name, pattern.chomp)
|
|
@@ -96,6 +100,8 @@ class Grok
|
|
|
96
100
|
end
|
|
97
101
|
|
|
98
102
|
@regexp = Regexp.new(@expanded_pattern)
|
|
103
|
+
@logger.debug("Grok compiled OK", :pattern => pattern,
|
|
104
|
+
:expanded_pattern => @expanded_pattern)
|
|
99
105
|
end # def compile
|
|
100
106
|
|
|
101
107
|
public
|
|
@@ -108,6 +114,7 @@ class Grok
|
|
|
108
114
|
grokmatch.start, grokmatch.end = match.offset(0)
|
|
109
115
|
grokmatch.grok = self
|
|
110
116
|
grokmatch.match = match
|
|
117
|
+
@logger.debug("Regexp match object", :names => match.names, :captures => match.captures)
|
|
111
118
|
return grokmatch
|
|
112
119
|
else
|
|
113
120
|
return false
|
data/lib/grok/pure/pile.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
require "grok-pure"
|
|
2
|
+
require "logger"
|
|
3
|
+
require "cabin"
|
|
2
4
|
|
|
3
5
|
# A grok pile is an easy way to have multiple patterns together so
|
|
4
6
|
# that you can try to match against each one.
|
|
@@ -7,12 +9,21 @@ require "grok-pure"
|
|
|
7
9
|
# try each one until a match is found.
|
|
8
10
|
class Grok
|
|
9
11
|
class Pile
|
|
12
|
+
attr_accessor :logger
|
|
13
|
+
|
|
10
14
|
def initialize
|
|
11
15
|
@groks = []
|
|
12
16
|
@patterns = {}
|
|
13
17
|
@pattern_files = []
|
|
18
|
+
@logger = Cabin::Channel.new
|
|
19
|
+
@logger.subscribe(Logger.new(STDOUT))
|
|
14
20
|
end # def initialize
|
|
15
21
|
|
|
22
|
+
def logger=(logger)
|
|
23
|
+
@logger = logger
|
|
24
|
+
@groks.each { |g| g.logger = logger }
|
|
25
|
+
end
|
|
26
|
+
|
|
16
27
|
# see Grok#add_pattern
|
|
17
28
|
def add_pattern(name, string)
|
|
18
29
|
@patterns[name] = string
|
|
@@ -29,6 +40,7 @@ class Grok
|
|
|
29
40
|
# see Grok#compile
|
|
30
41
|
def compile(pattern)
|
|
31
42
|
grok = Grok.new
|
|
43
|
+
grok.logger = @logger unless @logger.nil?
|
|
32
44
|
@patterns.each do |name, value|
|
|
33
45
|
grok.add_pattern(name, value)
|
|
34
46
|
end
|
|
@@ -36,6 +48,8 @@ class Grok
|
|
|
36
48
|
grok.add_patterns_from_file(path)
|
|
37
49
|
end
|
|
38
50
|
grok.compile(pattern)
|
|
51
|
+
@logger.info("Pile compiled new grok", :pattern => pattern,
|
|
52
|
+
:expanded_pattern => grok.expanded_pattern)
|
|
39
53
|
@groks << grok
|
|
40
54
|
end # def compile
|
|
41
55
|
|
metadata
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jls-grok
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.9.1
|
|
4
5
|
prerelease:
|
|
5
|
-
version: 0.9.0
|
|
6
6
|
platform: ruby
|
|
7
|
-
authors:
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
authors:
|
|
8
|
+
- Jordan Sissel
|
|
9
|
+
- Pete Fritchman
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
date: 2011-10-25 00:00:00.000000000Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: cabin
|
|
17
|
+
requirement: &17510060 !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ! '>='
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: *17510060
|
|
18
26
|
description: Grok ruby bindings - pattern match/extraction tool
|
|
19
|
-
email:
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
email:
|
|
28
|
+
- jls@semicomplete.com
|
|
29
|
+
- petef@databits.net
|
|
22
30
|
executables: []
|
|
23
|
-
|
|
24
31
|
extensions: []
|
|
25
|
-
|
|
26
32
|
extra_rdoc_files: []
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
- lib/grok/pure/match.rb
|
|
36
|
-
has_rdoc: true
|
|
33
|
+
files:
|
|
34
|
+
- lib/grok-pure.rb
|
|
35
|
+
- lib/grok.rb
|
|
36
|
+
- lib/grok/c-ext/pile.rb
|
|
37
|
+
- lib/grok/c-ext/match.rb
|
|
38
|
+
- lib/grok/pure/pile.rb
|
|
39
|
+
- lib/grok/pure/match.rb
|
|
40
|
+
- lib/Grok.rb
|
|
37
41
|
homepage: http://code.google.com/p/semicomplete/wiki/Grok
|
|
38
42
|
licenses: []
|
|
39
|
-
|
|
40
43
|
post_install_message:
|
|
41
44
|
rdoc_options: []
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
49
|
none: false
|
|
48
|
-
requirements:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
55
|
none: false
|
|
54
|
-
requirements:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
requirements:
|
|
57
|
+
- - ! '>='
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '0'
|
|
58
60
|
requirements: []
|
|
59
|
-
|
|
60
61
|
rubyforge_project:
|
|
61
|
-
rubygems_version: 1.
|
|
62
|
+
rubygems_version: 1.8.10
|
|
62
63
|
signing_key:
|
|
63
64
|
specification_version: 3
|
|
64
65
|
summary: grok bindings for ruby
|
|
65
66
|
test_files: []
|
|
66
|
-
|