logfmt 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis-ci.yml +1 -1
- data/README.md +7 -0
- data/lib/logfmt/parser.rb +14 -10
- data/lib/logfmt/version.rb +2 -2
- data/logfmt.gemspec +4 -4
- data/spec/logfmt/parser_spec.rb +17 -16
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ea9ce7afd32bfdaa73e9399460c34f6c5cf2a60
|
4
|
+
data.tar.gz: c54d8967a623133fbabfbf50d160fb284e62a207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 451bd0bc7ab6db03156c1bcd16277af82f36a597eef4d2a8e5ec7a989cbeb1224662a497918523478dc64850f868afb242a954453a882165027e27387ae186ae
|
7
|
+
data.tar.gz: 38780bd602894e7a57800ec52bbbe0325d476f155f5e09de3964232268d1906932576f576ce5d0d797dc34840d221e616f046a48330e19d40df4f0c94574a91f
|
data/.gitignore
CHANGED
data/.travis-ci.yml
CHANGED
data/README.md
ADDED
data/lib/logfmt/parser.rb
CHANGED
@@ -2,19 +2,23 @@ require "parslet"
|
|
2
2
|
|
3
3
|
module Logfmt
|
4
4
|
class Parser < Parslet::Parser
|
5
|
-
rule(:ident_byte) { match
|
6
|
-
rule(:string_byte) { match
|
7
|
-
rule(:garbage) { match
|
5
|
+
rule(:ident_byte) { match['^\s"='] }
|
6
|
+
rule(:string_byte) { match['^\\\\"'] }
|
7
|
+
rule(:garbage) { match['\s"='].repeat }
|
8
8
|
rule(:ident) { ident_byte >> ident_byte.repeat }
|
9
9
|
rule(:key) { ident }
|
10
10
|
rule(:value) {
|
11
|
-
|
11
|
+
ident.as(:value) |
|
12
|
+
str('"') >> (string_byte | str('\"')).repeat.as(:value) >> str('"')
|
12
13
|
}
|
13
14
|
rule(:pair) {
|
14
15
|
(key.as(:key) >> str('=') >> value) |
|
15
|
-
(key.as(:key) >> str('=')) |
|
16
|
+
(key.as(:key) >> str('=')) |
|
17
|
+
key.as(:key)
|
18
|
+
}
|
19
|
+
rule(:message) {
|
20
|
+
(garbage >> pair.as(:pair)).repeat.as(:message) >> garbage
|
16
21
|
}
|
17
|
-
rule(:message) { (garbage >> pair.as(:pair)).repeat.as(:message) >> garbage }
|
18
22
|
root(:message)
|
19
23
|
end
|
20
24
|
|
@@ -25,13 +29,13 @@ module Logfmt
|
|
25
29
|
(ob.is_a?(Array) ? ob : [ ob ]).inject({}) { |h, p| h[p.key] = p.val; h }
|
26
30
|
}
|
27
31
|
rule(:pair => { :key => simple(:key), :value => simple(:val) }) {
|
28
|
-
Pair.new(key.
|
32
|
+
Pair.new(key.to_s, val.to_s)
|
29
33
|
}
|
30
34
|
rule(:pair => { :key => simple(:key), :value => sequence(:val) }) {
|
31
|
-
Pair.new(key.
|
35
|
+
Pair.new(key.to_s, "")
|
32
36
|
}
|
33
37
|
rule(:pair => { :key => simple(:key) }) {
|
34
|
-
Pair.new(key.
|
38
|
+
Pair.new(key.to_s, true)
|
35
39
|
}
|
36
40
|
end
|
37
41
|
|
@@ -42,4 +46,4 @@ module Logfmt
|
|
42
46
|
tree = parser.parse(logs)
|
43
47
|
transformer.apply(tree)
|
44
48
|
end
|
45
|
-
end
|
49
|
+
end
|
data/lib/logfmt/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Logfmt
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
2
|
+
VERSION = "0.0.3"
|
3
|
+
end
|
data/logfmt.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
|
-
gem.add_dependency "parslet"
|
21
|
-
gem.add_development_dependency "rspec"
|
22
|
-
gem.add_development_dependency "rake"
|
23
|
-
end
|
20
|
+
gem.add_dependency "parslet", "~> 1.5"
|
21
|
+
gem.add_development_dependency "rspec", "~> 2.14"
|
22
|
+
gem.add_development_dependency "rake", "~> 10.1"
|
23
|
+
end
|
data/spec/logfmt/parser_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
require 'logfmt/parser'
|
3
4
|
|
@@ -14,61 +15,61 @@ describe Logfmt::Parser do
|
|
14
15
|
|
15
16
|
it 'parse key without value' do
|
16
17
|
data = Logfmt.parse("key")
|
17
|
-
expect(data).to eq({
|
18
|
+
expect(data).to eq({"key" => true})
|
18
19
|
end
|
19
20
|
|
20
21
|
it 'parse key without value and whitespace' do
|
21
22
|
data = Logfmt.parse(" key ")
|
22
|
-
expect(data).to eq({
|
23
|
+
expect(data).to eq({"key" => true})
|
23
24
|
end
|
24
25
|
|
25
26
|
it 'parse multiple single keys' do
|
26
27
|
data = Logfmt.parse("key1 key2")
|
27
|
-
expect(data).to eq({
|
28
|
+
expect(data).to eq({"key1" => true, "key2" => true})
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'parse unquoted value' do
|
31
32
|
data = Logfmt.parse("key=value")
|
32
|
-
expect(data).to eq({
|
33
|
+
expect(data).to eq({"key" => "value"})
|
33
34
|
end
|
34
35
|
|
35
36
|
it 'parse pairs' do
|
36
37
|
data = Logfmt.parse("key1=value1 key2=value2")
|
37
|
-
expect(data).to eq({
|
38
|
+
expect(data).to eq({"key1" => "value1", "key2" => "value2"})
|
38
39
|
end
|
39
40
|
|
40
41
|
it 'parse mixed single/non-single pairs' do
|
41
42
|
data = Logfmt.parse("key1=value1 key2")
|
42
|
-
expect(data).to eq({
|
43
|
+
expect(data).to eq({"key1" => "value1", "key2" => true})
|
43
44
|
end
|
44
45
|
|
45
46
|
it 'parse mixed pairs whatever the order' do
|
46
47
|
data = Logfmt.parse("key1 key2=value2")
|
47
|
-
expect(data).to eq({
|
48
|
+
expect(data).to eq({"key1" => true, "key2" => "value2"})
|
48
49
|
end
|
49
50
|
|
50
51
|
it 'parse quoted value' do
|
51
52
|
data = Logfmt.parse('key="quoted value"')
|
52
|
-
expect(data).to eq({
|
53
|
+
expect(data).to eq({"key" => "quoted value"})
|
53
54
|
end
|
54
55
|
|
55
|
-
it 'parse escaped quote value' do
|
56
|
-
data = Logfmt.parse('key="quoted \" value"')
|
57
|
-
expect(data).to eq({
|
56
|
+
it 'parse escaped quote value ' do
|
57
|
+
data = Logfmt.parse('key="quoted \" value" r="esc\t"')
|
58
|
+
expect(data).to eq({"key" => 'quoted " value', "r" => "esc\t"})
|
58
59
|
end
|
59
60
|
|
60
61
|
it 'parse mixed pairs' do
|
61
62
|
data = Logfmt.parse('key1="quoted \" value" key2 key3=value3')
|
62
|
-
expect(data).to eq({
|
63
|
+
expect(data).to eq({"key1" => 'quoted " value', "key2" => true, "key3" => "value3"})
|
63
64
|
end
|
64
65
|
|
65
66
|
it 'parse mixed characters pairs' do
|
66
|
-
data = Logfmt.parse('foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf')
|
67
|
-
expect(data).to eq({
|
67
|
+
data = Logfmt.parse('foo=bar a=14 baz="hello kitty" ƒ=2h3s cool%story=bro f %^asdf')
|
68
|
+
expect(data).to eq({"foo" => "bar", "a" => "14", "baz" => "hello kitty", "ƒ" => "2h3s", "cool%story" => "bro", "f" => true, "%^asdf" => true})
|
68
69
|
end
|
69
70
|
|
70
71
|
it 'parse pair with empty quote' do
|
71
72
|
data = Logfmt.parse('key=""')
|
72
|
-
expect(data).to eq({
|
73
|
+
expect(data).to eq({"key" => ""})
|
73
74
|
end
|
74
|
-
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logfmt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timothée Peignier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.14'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.14'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10.1'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '10.1'
|
55
55
|
description: Parse log lines in the logfmt style.
|
56
56
|
email:
|
57
57
|
- timothee.peignier@tryphon.org
|
@@ -59,10 +59,11 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .gitignore
|
63
|
-
- .rspec
|
64
|
-
- .travis-ci.yml
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis-ci.yml"
|
65
65
|
- Gemfile
|
66
|
+
- README.md
|
66
67
|
- Rakefile
|
67
68
|
- lib/logfmt.rb
|
68
69
|
- lib/logfmt/parser.rb
|
@@ -80,17 +81,17 @@ require_paths:
|
|
80
81
|
- lib
|
81
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
82
83
|
requirements:
|
83
|
-
- -
|
84
|
+
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
86
|
version: '0'
|
86
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
88
|
requirements:
|
88
|
-
- -
|
89
|
+
- - ">="
|
89
90
|
- !ruby/object:Gem::Version
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.2.2
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: Parse logfmt messages.
|