logfmt 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/bench.rb +2 -2
- data/lib/logfmt.rb +2 -2
- data/lib/logfmt/parser.rb +13 -15
- data/lib/logfmt/version.rb +1 -1
- data/logfmt.gemspec +8 -8
- data/spec/logfmt/parser_spec.rb +37 -37
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2327cc4b6b81e1f8697b774dd0100e94465d9f13
|
4
|
+
data.tar.gz: 81758010bbe3acd78c67f01aa5947a27b165c70e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 726f73839a6139edf96a8632cd5c8bb978eb884ccb4c1ddad021ba9dc5e623b6275182340ffe6a6546321e19c082fb79e1e6346878fe3f972214c32a0f833694
|
7
|
+
data.tar.gz: bf601bd78782b3fa6d52421b7a101a1c17f399c113ba033da34a535daaed62797e80e46668be3513d7483dc09115662fd900b665cdcc18a7125d4ed79e836f37
|
data/Rakefile
CHANGED
data/bench.rb
CHANGED
data/lib/logfmt.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'logfmt/version'
|
2
|
+
require 'logfmt/parser'
|
data/lib/logfmt/parser.rb
CHANGED
@@ -6,16 +6,16 @@ module Logfmt
|
|
6
6
|
QVALUE = 4
|
7
7
|
|
8
8
|
def self.numeric?(s)
|
9
|
-
|
9
|
+
s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.integer?(s)
|
13
|
-
|
13
|
+
s.match(/\A[-+]?[0-9]+\Z/)
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.parse(line)
|
17
17
|
output = {}
|
18
|
-
key, value =
|
18
|
+
key, value = '', ''
|
19
19
|
escaped = false
|
20
20
|
state = GARBAGE
|
21
21
|
i = 0
|
@@ -33,15 +33,13 @@ module Logfmt
|
|
33
33
|
state = KEY
|
34
34
|
key << c
|
35
35
|
elsif c == '='
|
36
|
-
output[key.strip
|
36
|
+
output[key.strip] = true
|
37
37
|
state = EQUAL
|
38
38
|
else
|
39
|
-
output[key.strip
|
39
|
+
output[key.strip] = true
|
40
40
|
state = GARBAGE
|
41
41
|
end
|
42
|
-
if i >= line.length
|
43
|
-
output[key.strip()] = true
|
44
|
-
end
|
42
|
+
output[key.strip] = true if i >= line.length
|
45
43
|
next
|
46
44
|
end
|
47
45
|
if state == EQUAL
|
@@ -49,7 +47,7 @@ module Logfmt
|
|
49
47
|
value = c
|
50
48
|
state = IVALUE
|
51
49
|
elsif c == '"'
|
52
|
-
value =
|
50
|
+
value = ''
|
53
51
|
escaped = false
|
54
52
|
state = QVALUE
|
55
53
|
else
|
@@ -61,18 +59,18 @@ module Logfmt
|
|
61
59
|
elsif numeric?(value)
|
62
60
|
value = Float(value)
|
63
61
|
end
|
64
|
-
output[key.strip
|
62
|
+
output[key.strip] = value || true
|
65
63
|
end
|
66
64
|
next
|
67
65
|
end
|
68
66
|
if state == IVALUE
|
69
|
-
if
|
67
|
+
if !(c > ' ' && c != '"' && c != '=')
|
70
68
|
if integer?(value)
|
71
69
|
value = Integer(value)
|
72
70
|
elsif numeric?(value)
|
73
71
|
value = Float(value)
|
74
72
|
end
|
75
|
-
output[key.strip
|
73
|
+
output[key.strip] = value
|
76
74
|
state = GARBAGE
|
77
75
|
else
|
78
76
|
value << c
|
@@ -83,21 +81,21 @@ module Logfmt
|
|
83
81
|
elsif numeric?(value)
|
84
82
|
value = Float(value)
|
85
83
|
end
|
86
|
-
output[key.strip
|
84
|
+
output[key.strip] = value
|
87
85
|
end
|
88
86
|
next
|
89
87
|
end
|
90
88
|
if state == QVALUE
|
91
89
|
if c == '\\'
|
92
90
|
escaped = true
|
93
|
-
value <<
|
91
|
+
value << '\\'
|
94
92
|
elsif c == '"'
|
95
93
|
if escaped
|
96
94
|
escaped = false
|
97
95
|
value << c
|
98
96
|
next
|
99
97
|
end
|
100
|
-
output[key.strip
|
98
|
+
output[key.strip] = value
|
101
99
|
state = GARBAGE
|
102
100
|
else
|
103
101
|
escaped = false
|
data/lib/logfmt/version.rb
CHANGED
data/logfmt.gemspec
CHANGED
@@ -4,19 +4,19 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'logfmt/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'logfmt'
|
8
8
|
gem.version = Logfmt::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
9
|
+
gem.authors = ['Timothée Peignier']
|
10
|
+
gem.email = ['timothee.peignier@tryphon.org']
|
11
11
|
gem.description = %q{Parse log lines in the logfmt style.}
|
12
12
|
gem.summary = %q{Parse logfmt messages.}
|
13
|
-
gem.homepage =
|
13
|
+
gem.homepage = 'https://github.com/cyberdelia/logfmt-ruby'
|
14
14
|
gem.license = 'MIT'
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
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
|
-
gem.require_paths = [
|
20
|
-
gem.add_development_dependency
|
21
|
-
gem.add_development_dependency
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
21
|
+
gem.add_development_dependency 'rake', '~> 10.3'
|
22
22
|
end
|
data/spec/logfmt/parser_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'logfmt/parser'
|
|
4
4
|
|
5
5
|
describe Logfmt do
|
6
6
|
it 'parse empty log line' do
|
7
|
-
data = Logfmt.parse(
|
7
|
+
data = Logfmt.parse('')
|
8
8
|
expect(data).to eq({})
|
9
9
|
end
|
10
10
|
|
@@ -14,121 +14,121 @@ describe Logfmt do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'parse key without value' do
|
17
|
-
data = Logfmt.parse(
|
18
|
-
expect(data).to eq(
|
17
|
+
data = Logfmt.parse('key')
|
18
|
+
expect(data).to eq('key' => true)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'parse key without value and whitespace' do
|
22
|
-
data = Logfmt.parse(
|
23
|
-
expect(data).to eq(
|
22
|
+
data = Logfmt.parse(' key ')
|
23
|
+
expect(data).to eq('key' => true)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'parse multiple single keys' do
|
27
|
-
data = Logfmt.parse(
|
28
|
-
expect(data).to eq(
|
27
|
+
data = Logfmt.parse('key1 key2')
|
28
|
+
expect(data).to eq('key1' => true, 'key2' => true)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'parse unquoted value' do
|
32
|
-
data = Logfmt.parse(
|
33
|
-
expect(data).to eq(
|
32
|
+
data = Logfmt.parse('key=value')
|
33
|
+
expect(data).to eq('key' => 'value')
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'parse pairs' do
|
37
|
-
data = Logfmt.parse(
|
38
|
-
expect(data).to eq(
|
37
|
+
data = Logfmt.parse('key1=value1 key2=value2')
|
38
|
+
expect(data).to eq('key1' => 'value1', 'key2' => 'value2')
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'parse mixed single/non-single pairs' do
|
42
|
-
data = Logfmt.parse(
|
43
|
-
expect(data).to eq(
|
42
|
+
data = Logfmt.parse('key1=value1 key2')
|
43
|
+
expect(data).to eq('key1' => 'value1', 'key2' => true)
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'parse mixed pairs whatever the order' do
|
47
|
-
data = Logfmt.parse(
|
48
|
-
expect(data).to eq(
|
47
|
+
data = Logfmt.parse('key1 key2=value2')
|
48
|
+
expect(data).to eq('key1' => true, 'key2' => 'value2')
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'parse quoted value' do
|
52
52
|
data = Logfmt.parse('key="quoted value"')
|
53
|
-
expect(data).to eq(
|
53
|
+
expect(data).to eq('key' => 'quoted value')
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'parse escaped quote value ' do
|
57
57
|
data = Logfmt.parse('key="quoted \" value" r="esc\t"')
|
58
|
-
expect(data).to eq(
|
58
|
+
expect(data).to eq('key' => 'quoted \" value', 'r' => 'esc\\t')
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'parse mixed pairs' do
|
62
62
|
data = Logfmt.parse('key1="quoted \" value" key2 key3=value3')
|
63
|
-
expect(data).to eq(
|
63
|
+
expect(data).to eq('key1' => 'quoted \" value', 'key2' => true, 'key3' => 'value3')
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'parse mixed characters pairs' do
|
67
67
|
data = Logfmt.parse('foo=bar a=14 baz="hello kitty" ƒ=2h3s cool%story=bro f %^asdf')
|
68
|
-
expect(data).to eq(
|
68
|
+
expect(data).to eq('foo' => 'bar', 'a' => 14, 'baz' => 'hello kitty',
|
69
|
+
'ƒ' => '2h3s', 'cool%story' => 'bro', 'f' => true, '%^asdf' => true)
|
69
70
|
end
|
70
71
|
|
71
72
|
it 'parse pair with empty quote' do
|
72
73
|
data = Logfmt.parse('key=""')
|
73
|
-
expect(data).to eq(
|
74
|
+
expect(data).to eq('key' => '')
|
74
75
|
end
|
75
76
|
|
76
77
|
# Currently, the value comes back as "true", which could mess up stats
|
77
78
|
# Really, only "true" should come back as "true"
|
78
79
|
# it 'parse 1 as integer type' do
|
79
80
|
# data = Logfmt.parse('key=1')
|
80
|
-
# expect(data[
|
81
|
+
# expect(data['key'].class).to eq(Fixnum)
|
81
82
|
# end
|
82
83
|
|
83
84
|
it 'parse positive integer as integer type' do
|
84
85
|
data = Logfmt.parse('key=234')
|
85
|
-
expect(data[
|
86
|
-
expect(data[
|
86
|
+
expect(data['key']).to eq(234)
|
87
|
+
expect(data['key'].class).to eq(Fixnum)
|
87
88
|
end
|
88
89
|
|
89
90
|
it 'parse negative integer as integer type' do
|
90
91
|
data = Logfmt.parse('key=-3428')
|
91
|
-
expect(data[
|
92
|
-
expect(data[
|
92
|
+
expect(data['key']).to eq(-3428)
|
93
|
+
expect(data['key'].class).to eq(Fixnum)
|
93
94
|
end
|
94
95
|
|
95
|
-
|
96
96
|
it 'parse positive float as float type' do
|
97
97
|
data = Logfmt.parse('key=3.342')
|
98
|
-
expect(data[
|
99
|
-
expect(data[
|
98
|
+
expect(data['key']).to eq(3.342)
|
99
|
+
expect(data['key'].class).to eq(Float)
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'parse negative float as float type' do
|
103
103
|
data = Logfmt.parse('key=-0.9934')
|
104
|
-
expect(data[
|
105
|
-
expect(data[
|
104
|
+
expect(data['key']).to eq(-0.9934)
|
105
|
+
expect(data['key'].class).to eq(Float)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'parse exponential float as float type' do
|
109
109
|
data = Logfmt.parse('key=2.342342342342344e+18')
|
110
|
-
expect(data[
|
111
|
-
expect(data[
|
110
|
+
expect(data['key']).to eq(2.342342342342344e+18)
|
111
|
+
expect(data['key'].class).to eq(Float)
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'parse quoted integer as string type' do
|
115
115
|
data = Logfmt.parse('key="234"')
|
116
|
-
expect(data[
|
116
|
+
expect(data['key'].class).to eq(String)
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'parse quoted float as string type' do
|
120
120
|
data = Logfmt.parse('key="3.14"')
|
121
|
-
expect(data[
|
121
|
+
expect(data['key'].class).to eq(String)
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'parse IP address as string type' do
|
125
125
|
data = Logfmt.parse('key=10.10.10.1')
|
126
|
-
expect(data[
|
126
|
+
expect(data['key'].class).to eq(String)
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'parse last as integer type' do
|
130
130
|
data = Logfmt.parse('key1=4 key2=9')
|
131
|
-
expect(data[
|
132
|
-
expect(data[
|
131
|
+
expect(data['key1']).to eq(4)
|
132
|
+
expect(data['key2']).to eq(9)
|
133
133
|
end
|
134
134
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
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: 2014-
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -85,4 +85,3 @@ summary: Parse logfmt messages.
|
|
85
85
|
test_files:
|
86
86
|
- spec/logfmt/parser_spec.rb
|
87
87
|
- spec/spec_helper.rb
|
88
|
-
has_rdoc:
|