fluent-plugin-formatter_sprintf 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +1 -1
- data/fluent-plugin-formatter_sprintf.gemspec +1 -1
- data/lib/fluent/plugin/formatter_sprintf.rb +16 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5675b240999ae98824ca04a279b71c761cc7ab1b
|
4
|
+
data.tar.gz: 9c2cbc6f59ce9b2abdefd0e6cb79b5e6c0791dd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dfbd9fa5a68e6587818b352b0f63b0b5d73756714ae90f6153314bd2892ec999359f49b9abb2c2d930405d79d0bce5ee792f3bd72acca3debfcc91c6c0c3a8a
|
7
|
+
data.tar.gz: 21887079b92d92c83f8b426a4b94507ea4117dee35f17f26d938718eb0968f786a37d94803005dcf378ffe0a30748f5e11778659391d1056f4793c24c70ea54a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# fluent-plugin-formatter_sprintf
|
2
2
|
|
3
|
-
[](http://travis-ci.org/toyama0919/fluent-plugin-formatter_sprintf)
|
4
4
|
|
5
5
|
Fluentd sprintf formatter plugin
|
6
6
|
|
@@ -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.2"
|
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"
|
@@ -7,6 +7,8 @@ module Fluent
|
|
7
7
|
include HandleTagAndTimeMixin
|
8
8
|
|
9
9
|
config_param :sprintf_format, :string
|
10
|
+
config_param :sprintf_blank_string, :string, :default => nil
|
11
|
+
config_param :sprintf_blank_record_format, :string, :default => nil
|
10
12
|
|
11
13
|
def initialize
|
12
14
|
super
|
@@ -18,6 +20,11 @@ module Fluent
|
|
18
20
|
r = /\$\{([^}]+)\}/
|
19
21
|
@keys = @sprintf_format.scan(r).map{ |key| key.first }
|
20
22
|
@sprintf_format = @sprintf_format.gsub(/\$\{([^}]+)\}/, '%s')
|
23
|
+
if @sprintf_blank_record_format
|
24
|
+
@sprintf_blank_record_keys = @sprintf_blank_record_format.scan(r).map{ |key| key.first }
|
25
|
+
@sprintf_blank_record_format = @sprintf_blank_record_format.gsub(/\$\{([^}]+)\}/, '%s')
|
26
|
+
end
|
27
|
+
|
21
28
|
begin
|
22
29
|
@sprintf_format % @keys
|
23
30
|
rescue ArgumentError => e
|
@@ -26,16 +33,22 @@ module Fluent
|
|
26
33
|
end
|
27
34
|
|
28
35
|
def format(tag, time, record)
|
29
|
-
|
36
|
+
if record.empty? && @sprintf_blank_record_format
|
37
|
+
return @sprintf_blank_record_format % get_values(@sprintf_blank_record_keys, tag, time, record)
|
38
|
+
end
|
39
|
+
@sprintf_format % get_values(@keys, tag, time, record)
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_values(keys, tag, time, record)
|
43
|
+
keys.map{ |key|
|
30
44
|
if key == 'tag'
|
31
45
|
tag
|
32
46
|
elsif key == 'time'
|
33
47
|
Time.at(time).strftime(@time_format)
|
34
48
|
else
|
35
|
-
record[key]
|
49
|
+
record[key] || @sprintf_blank_string
|
36
50
|
end
|
37
51
|
}
|
38
|
-
@sprintf_format % values
|
39
52
|
end
|
40
53
|
end
|
41
54
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Toyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -126,3 +126,4 @@ 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:
|