logfmt 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/logfmt/parser.rb +10 -10
- data/lib/logfmt/version.rb +1 -1
- data/spec/logfmt/parser_spec.rb +22 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d84880517339f8a0d4e92bec5c50a60e1565616
|
4
|
+
data.tar.gz: f49a8ab504c1c50312d585e3b4f2ed01d70bcf9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7880b117caee1ef7e794c04e59362db10076c58d58a28bbf360d9a71a56cc40cc089e7298f9a7f528a2bf3f304f1a45de68c9a24f2b419ff7afd3c8a4d3130d
|
7
|
+
data.tar.gz: d4f7b9e924dbeed9ef56c8be8e1e3d3109ea6c8e96d52da77ad06b34c5098639c4e00a8c45a463f442fbc6b56fa4cea9fb8f9d7cc1e2be82a693c9f6ba4a7eee
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,4 +4,4 @@ Parse log lines on the logfmt style:
|
|
4
4
|
|
5
5
|
>> require "logfmt"
|
6
6
|
>> Logfmt.parse('foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf')
|
7
|
-
=> {"foo"=>"bar", "a"=>
|
7
|
+
=> {"foo"=>"bar", "a"=>14, "baz"=>"hello kitty", "cool%story"=>"bro", "f"=>true, "%^asdf"=>true}
|
data/lib/logfmt/parser.rb
CHANGED
@@ -6,11 +6,11 @@ module Logfmt
|
|
6
6
|
QVALUE = 4
|
7
7
|
|
8
8
|
def self.numeric?(s)
|
9
|
-
s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/)
|
9
|
+
s.is_a?(Numeric) || s.to_s.match(/\A[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\Z/)
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.integer?(s)
|
13
|
-
s.match(/\A[-+]?[0-9]+\Z/)
|
13
|
+
s.is_a?(Integer) || s.to_s.match(/\A[-+]?[0-9]+\Z/)
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.parse(line)
|
@@ -55,20 +55,20 @@ module Logfmt
|
|
55
55
|
end
|
56
56
|
if i >= line.length
|
57
57
|
if integer?(value)
|
58
|
-
value =
|
58
|
+
value = value.to_i
|
59
59
|
elsif numeric?(value)
|
60
|
-
value =
|
60
|
+
value = value.to_f
|
61
61
|
end
|
62
62
|
output[key.strip] = value || true
|
63
63
|
end
|
64
64
|
next
|
65
65
|
end
|
66
66
|
if state == IVALUE
|
67
|
-
if !(c > ' ' && c != '"'
|
67
|
+
if !(c > ' ' && c != '"')
|
68
68
|
if integer?(value)
|
69
|
-
value =
|
69
|
+
value = value.to_i
|
70
70
|
elsif numeric?(value)
|
71
|
-
value =
|
71
|
+
value = value.to_f
|
72
72
|
end
|
73
73
|
output[key.strip] = value
|
74
74
|
state = GARBAGE
|
@@ -77,9 +77,9 @@ module Logfmt
|
|
77
77
|
end
|
78
78
|
if i >= line.length
|
79
79
|
if integer?(value)
|
80
|
-
value =
|
80
|
+
value = value.to_i
|
81
81
|
elsif numeric?(value)
|
82
|
-
value =
|
82
|
+
value = value.to_f
|
83
83
|
end
|
84
84
|
output[key.strip] = value
|
85
85
|
end
|
@@ -92,7 +92,7 @@ module Logfmt
|
|
92
92
|
elsif c == '"'
|
93
93
|
if escaped
|
94
94
|
escaped = false
|
95
|
-
value << c
|
95
|
+
value.chop! << c
|
96
96
|
next
|
97
97
|
end
|
98
98
|
output[key.strip] = value
|
data/lib/logfmt/version.rb
CHANGED
data/spec/logfmt/parser_spec.rb
CHANGED
@@ -55,12 +55,12 @@ describe Logfmt do
|
|
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('key' => 'quoted
|
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('key1' => 'quoted
|
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
|
@@ -131,4 +131,24 @@ describe Logfmt do
|
|
131
131
|
expect(data['key1']).to eq(4)
|
132
132
|
expect(data['key2']).to eq(9)
|
133
133
|
end
|
134
|
+
|
135
|
+
it 'parse string containing quotes' do
|
136
|
+
data = Logfmt.parse('key1="{\"msg\": \"hello\tworld\"}"')
|
137
|
+
expect(data['key1']).to eq('{"msg": "hello\tworld"}')
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'parse value containing equal sign' do
|
141
|
+
query = 'position=44.80450799126121%2C33.58320759981871&uid=1'
|
142
|
+
data = Logfmt.parse("method=GET query=#{query} status=200")
|
143
|
+
expect(data).to eq(
|
144
|
+
'method' => 'GET',
|
145
|
+
'query' => query,
|
146
|
+
'status' => 200
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'parses integers correctly' do
|
151
|
+
data = Logfmt.parse('key=111 ')
|
152
|
+
expect(data['key']).to eq(111)
|
153
|
+
end
|
134
154
|
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.8
|
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: 2016-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.6.8
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Parse logfmt messages.
|