fluent-plugin-formatter_sprintf 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -2
- data/README.md +18 -0
- data/fluent-plugin-formatter_sprintf.gemspec +1 -1
- data/lib/fluent/plugin/formatter_sprintf.rb +18 -7
- data/sample/fluent.conf +6 -1
- data/test/test_formatter_sprintf.rb +62 -5
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c29fa74f14ed89372ce1790fc6e840cb18bd026c
|
4
|
+
data.tar.gz: 25575cb703755f1039806fa596686ab645b957dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94666c65e0d2321805d2207ca2f8ab800df4963be57ee09d3a611ae6895417f60df6f5b4b38062338fbe512d3cb717a1584309739309854936545bef5e9e57d4
|
7
|
+
data.tar.gz: 81bf567361de1e809d011e9d18c291ef2b090b843d9e2d445b93d8d99f97a01ff51c286d2de77c7c179da124b50a1b2229b1f6d96d8f419df6ad97b5a0158488
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -53,6 +53,24 @@ gem install fluent-plugin-formatter_sprintf
|
|
53
53
|
</match>
|
54
54
|
```
|
55
55
|
|
56
|
+
### blank string(include [nil, empty?, blank?])
|
57
|
+
|
58
|
+
```apache
|
59
|
+
format sprintf
|
60
|
+
sprintf_format "${tag} ${time} ${url} ${ip_address}\n"
|
61
|
+
sprintf_blank_string -
|
62
|
+
```
|
63
|
+
|
64
|
+
##### input
|
65
|
+
```json
|
66
|
+
2016-03-15 14:21:40 +0900 analysis.pageview: { "url": null, "ip_address": null }
|
67
|
+
```
|
68
|
+
|
69
|
+
##### output
|
70
|
+
```
|
71
|
+
analysis.pageview 2016-01-01 00:00:00 - -
|
72
|
+
```
|
73
|
+
|
56
74
|
### bad syntax(at error)
|
57
75
|
|
58
76
|
sprintf_format "%s ${tag} ${time} ${url} ${ip_address}\n"
|
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "fluent-plugin-formatter_sprintf"
|
6
|
-
s.version = "0.0.
|
6
|
+
s.version = "0.0.4"
|
7
7
|
s.authors = ["Hiroshi Toyama"]
|
8
8
|
s.email = ["toyama0919@gmail.com"]
|
9
9
|
s.homepage = "https://github.com/toyama0919/fluent-plugin-formatter_sprintf"
|
@@ -41,15 +41,26 @@ module Fluent
|
|
41
41
|
|
42
42
|
def get_values(keys, tag, time, record)
|
43
43
|
keys.map{ |key|
|
44
|
-
|
45
|
-
tag
|
46
|
-
elsif key == 'time'
|
47
|
-
Time.at(time).strftime(@time_format)
|
48
|
-
else
|
49
|
-
(record[key].nil? || record[key].empty?) ? @sprintf_blank_string : record[key]
|
50
|
-
end
|
44
|
+
get_value(key, tag, time, record)
|
51
45
|
}
|
52
46
|
end
|
47
|
+
|
48
|
+
def get_value(key, tag, time, record)
|
49
|
+
if key == 'tag'
|
50
|
+
tag
|
51
|
+
elsif key == 'time'
|
52
|
+
Time.at(time).strftime(@time_format)
|
53
|
+
else
|
54
|
+
return @sprintf_blank_string if record[key].nil?
|
55
|
+
if record[key].respond_to?(:empty?) && record[key].empty?
|
56
|
+
return @sprintf_blank_string
|
57
|
+
end
|
58
|
+
if record[key].class == String && record[key].strip.empty?
|
59
|
+
return @sprintf_blank_string
|
60
|
+
end
|
61
|
+
record[key]
|
62
|
+
end
|
63
|
+
end
|
53
64
|
end
|
54
65
|
end
|
55
66
|
end
|
data/sample/fluent.conf
CHANGED
@@ -8,11 +8,16 @@ class SprintfFormatterTest < ::Test::Unit::TestCase
|
|
8
8
|
@time = Fluent::Engine.now
|
9
9
|
end
|
10
10
|
|
11
|
+
def create_driver(conf={})
|
12
|
+
Fluent::Test::FormatterTestDriver.new(Fluent::TextFormatter::SprintfFormatter).configure(conf)
|
13
|
+
end
|
14
|
+
|
11
15
|
def configure(conf)
|
16
|
+
@formatter = create_driver(conf)
|
12
17
|
end
|
13
18
|
|
14
19
|
def test_format_space
|
15
|
-
|
20
|
+
configure({'sprintf_format' => "${tag} ${url} ${ip_address}\n"})
|
16
21
|
tag = 'file.test'
|
17
22
|
record = {"url" => "/", "ip_address" => "127.0.0.1"}
|
18
23
|
|
@@ -21,7 +26,7 @@ class SprintfFormatterTest < ::Test::Unit::TestCase
|
|
21
26
|
end
|
22
27
|
|
23
28
|
def test_format_tsv
|
24
|
-
|
29
|
+
configure({'sprintf_format' => "${tag}\t${url}\t${ip_address}\n"})
|
25
30
|
tag = 'file.test'
|
26
31
|
record = {"url" => "/", "ip_address" => "127.0.0.1"}
|
27
32
|
|
@@ -31,15 +36,67 @@ class SprintfFormatterTest < ::Test::Unit::TestCase
|
|
31
36
|
|
32
37
|
def test_format_literal_error
|
33
38
|
assert_raise(Fluent::ConfigError) do
|
34
|
-
|
39
|
+
configure({'sprintf_format' => "%s\t${url}\t${ip_address}\n"})
|
35
40
|
end
|
36
41
|
|
37
42
|
assert_raise(Fluent::ConfigError) do
|
38
|
-
|
43
|
+
configure({'sprintf_format' => "${url}\t${ip_address}\t%s"})
|
39
44
|
end
|
40
45
|
|
41
46
|
assert_raise(Fluent::ConfigError) do
|
42
|
-
|
47
|
+
configure({'sprintf_format' => "${url}\t%s\t${ip_address}\t"})
|
43
48
|
end
|
44
49
|
end
|
50
|
+
|
51
|
+
def test_fixnum
|
52
|
+
configure({'sprintf_format' => "${tag}\t${id}\t${ip_address}\n"})
|
53
|
+
tag = 'file.test'
|
54
|
+
record = {"id" => 1, "ip_address" => "127.0.0.1"}
|
55
|
+
|
56
|
+
formatted = @formatter.format(tag, @time, record)
|
57
|
+
assert_equal("file.test\t1\t127.0.0.1\n", formatted)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_sprintf_blank_string
|
61
|
+
configure(
|
62
|
+
{
|
63
|
+
'sprintf_format' => "${tag}\t${id}\t${ip_address}\t${space}\n",
|
64
|
+
'sprintf_blank_string' => "-",
|
65
|
+
}
|
66
|
+
)
|
67
|
+
tag = 'file.test'
|
68
|
+
record = {"id" => nil, "ip_address" => "", "space" => " "}
|
69
|
+
|
70
|
+
formatted = @formatter.format(tag, @time, record)
|
71
|
+
assert_equal("file.test\t-\t-\t-\n", formatted)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_sprintf_blank_string_with_array
|
75
|
+
configure(
|
76
|
+
{
|
77
|
+
'sprintf_format' => "${tag}\t${array}\n",
|
78
|
+
'sprintf_blank_string' => "-",
|
79
|
+
}
|
80
|
+
)
|
81
|
+
tag = 'file.test'
|
82
|
+
record = {"array" => []}
|
83
|
+
|
84
|
+
formatted = @formatter.format(tag, @time, record)
|
85
|
+
assert_equal("file.test\t-\n", formatted)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_sprintf_blank_record_format
|
89
|
+
configure(
|
90
|
+
{
|
91
|
+
'sprintf_format' => "${tag}\t${id}\t${ip_address}\t${space}\n",
|
92
|
+
'sprintf_blank_string' => "-",
|
93
|
+
'sprintf_blank_record_format' => "---\n",
|
94
|
+
}
|
95
|
+
)
|
96
|
+
tag = 'file.test'
|
97
|
+
record = {}
|
98
|
+
|
99
|
+
formatted = @formatter.format(tag, @time, record)
|
100
|
+
assert_equal("---\n", formatted)
|
101
|
+
end
|
45
102
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-formatter_sprintf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Toyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -119,11 +119,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
requirements: []
|
121
121
|
rubyforge_project: fluent-plugin-formatter_sprintf
|
122
|
-
rubygems_version: 2.4.
|
122
|
+
rubygems_version: 2.4.8
|
123
123
|
signing_key:
|
124
124
|
specification_version: 4
|
125
125
|
summary: Fluentd Free formatter plugin, Use sprintf.
|
126
126
|
test_files:
|
127
127
|
- test/helper.rb
|
128
128
|
- test/test_formatter_sprintf.rb
|
129
|
-
has_rdoc:
|