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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a31f473ee9fde670a1d317e2475c4d2b53f3c4b1
4
- data.tar.gz: 07bd647465be8fa975fa9139be574f3ab7210734
3
+ metadata.gz: 8ea9ce7afd32bfdaa73e9399460c34f6c5cf2a60
4
+ data.tar.gz: c54d8967a623133fbabfbf50d160fb284e62a207
5
5
  SHA512:
6
- metadata.gz: 2c2a583a06066f3685852a2cc843abef98d6db3006598c40b832e4ddb5a6cc5c4363c83ee69495a55ce78936a51c685f2d9a1fb1f1df78448f5b50ad2b8e4c91
7
- data.tar.gz: a80d757664e17b368cdfb25acf45335e46f9aabd55790bb0201f32ea3d56c07e7b5d0f8f0b62bae7aa2f024bc3838302ee4260e73e4c9ff391418202f3eb769f
6
+ metadata.gz: 451bd0bc7ab6db03156c1bcd16277af82f36a597eef4d2a8e5ec7a989cbeb1224662a497918523478dc64850f868afb242a954453a882165027e27387ae186ae
7
+ data.tar.gz: 38780bd602894e7a57800ec52bbbe0325d476f155f5e09de3964232268d1906932576f576ce5d0d797dc34840d221e616f046a48330e19d40df4f0c94574a91f
data/.gitignore CHANGED
@@ -14,4 +14,5 @@ rdoc
14
14
  spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
- tmp
17
+ tmp
18
+ .ruby-version
data/.travis-ci.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
4
  - 2.0.0
5
+ - 2.1.1
6
6
  script: bundle exec rspec spec
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # Logfmt
2
+
3
+ Parse log lines on the logfmt style:
4
+
5
+ >> require "logfmt"
6
+ >> Logfmt.parse('foo=bar a=14 baz="hello kitty" cool%story=bro f %^asdf')
7
+ => {"foo"=>"bar", "a"=>"14", "baz"=>"hello kitty", "cool%story"=>"bro", "f"=>true, "%^asdf"=>true}
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("[^ \t\r\n\f\"=]") }
6
- rule(:string_byte) { match("[^\"\\\\]") }
7
- rule(:garbage) { match("[ \t\r\n\f\"=]").repeat }
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
- (ident.as(:value) | (str('"') >> (string_byte | str('\\') >> str('"')).repeat.as(:value) >> str('"')))
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('=')) | key.as(:key)
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.to_sym, val.to_s)
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.to_sym, "")
35
+ Pair.new(key.to_s, "")
32
36
  }
33
37
  rule(:pair => { :key => simple(:key) }) {
34
- Pair.new(key.to_sym, true)
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
@@ -1,3 +1,3 @@
1
1
  module Logfmt
2
- VERSION = "0.0.2"
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
@@ -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({:key => true})
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({:key => true})
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({:key1 => true, :key2 => true})
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({:key => "value"})
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({:key1 => "value1", :key2 => "value2"})
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({:key1 => "value1", :key2 => true})
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({:key1 => true, :key2 => "value2"})
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({:key => "quoted value"})
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({:key => 'quoted " value'})
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({:key1 => 'quoted " value', :key2 => true, :key3 => "value3"})
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({:foo => "bar", :a => "14", :baz => "hello kitty", :"cool%story" => "bro", :f => true, :"%^asdf" => true})
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({:key => ""})
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.2
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: 2013-05-06 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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.0.0
94
+ rubygems_version: 2.2.2
94
95
  signing_key:
95
96
  specification_version: 4
96
97
  summary: Parse logfmt messages.