fluent-plugin-record-modifier 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +13 -0
- data/ChangeLog +6 -0
- data/README.md +19 -0
- data/VERSION +1 -1
- data/lib/fluent/plugin/out_record_modifier.rb +36 -1
- data/test/out_record_modifier.rb +31 -0
- metadata +5 -4
data/.travis.yml
ADDED
data/ChangeLog
CHANGED
data/README.md
CHANGED
@@ -33,6 +33,25 @@ then you got new record like below:
|
|
33
33
|
{"message":"hello world!", "gen_host":"oreore-mac.local", "foo":"bar"}
|
34
34
|
```
|
35
35
|
|
36
|
+
### char_encoding
|
37
|
+
|
38
|
+
Fluentd including some plugins treats the logs as a BINARY by default to forward.
|
39
|
+
But an user sometimes processes the logs depends on their requirements, e.g. handling char encoding correctly.
|
40
|
+
|
41
|
+
`char_encoding` parameter is useful for this case.
|
42
|
+
|
43
|
+
```conf
|
44
|
+
<match pattern>
|
45
|
+
type record_modifier
|
46
|
+
|
47
|
+
# set UTF-8 encoding information to string.
|
48
|
+
char_encoding utf-8
|
49
|
+
|
50
|
+
# change char encoding from 'UTF-8' to 'EUC-JP'
|
51
|
+
char_encoding utf-8:euc-jp
|
52
|
+
</match>
|
53
|
+
```
|
54
|
+
|
36
55
|
### Mixins
|
37
56
|
|
38
57
|
* [SetTagKeyMixin](https://github.com/fluent/fluentd/blob/master/lib/fluent/mixin.rb#L181)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -5,11 +5,12 @@ module Fluent
|
|
5
5
|
Fluent::Plugin.register_output('record_modifier', self)
|
6
6
|
|
7
7
|
config_param :tag, :string
|
8
|
+
config_param :char_encoding, :string, :default => nil
|
8
9
|
|
9
10
|
include SetTagKeyMixin
|
10
11
|
include Fluent::Mixin::ConfigPlaceholders
|
11
12
|
|
12
|
-
BUILTIN_CONFIGURATIONS = %W(type tag include_tag_key tag_key)
|
13
|
+
BUILTIN_CONFIGURATIONS = %W(type tag include_tag_key tag_key char_encoding)
|
13
14
|
|
14
15
|
def configure(conf)
|
15
16
|
super
|
@@ -21,6 +22,22 @@ module Fluent
|
|
21
22
|
@map[k] = v
|
22
23
|
end
|
23
24
|
}
|
25
|
+
|
26
|
+
if @char_encoding
|
27
|
+
from, to = @char_encoding.split(':', 2)
|
28
|
+
@from_enc = Encoding.find(from)
|
29
|
+
@to_enc = Encoding.find(to) if to
|
30
|
+
|
31
|
+
m = if @to_enc
|
32
|
+
method(:convert_encoding)
|
33
|
+
else
|
34
|
+
method(:set_encoding)
|
35
|
+
end
|
36
|
+
|
37
|
+
(class << self; self; end).module_eval do
|
38
|
+
define_method(:change_encoding, m)
|
39
|
+
end
|
40
|
+
end
|
24
41
|
end
|
25
42
|
|
26
43
|
def emit(tag, es, chain)
|
@@ -39,7 +56,25 @@ module Fluent
|
|
39
56
|
record[k] = v
|
40
57
|
}
|
41
58
|
|
59
|
+
record = change_encoding(record) if @char_encoding
|
42
60
|
record
|
43
61
|
end
|
62
|
+
|
63
|
+
def set_encoding(record)
|
64
|
+
record.each_pair { |k, v|
|
65
|
+
if v.is_a?(String)
|
66
|
+
v.force_encoding(@from_enc)
|
67
|
+
end
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def convert_encoding(record)
|
72
|
+
record.each_pair { |k, v|
|
73
|
+
if v.is_a?(String)
|
74
|
+
v.force_encoding(@from_enc) if v.encoding == Encoding::BINARY
|
75
|
+
v.encode!(@to_enc, @from_enc, :invalid => :replace, :undef => :replace)
|
76
|
+
end
|
77
|
+
}
|
78
|
+
end
|
44
79
|
end
|
45
80
|
end
|
data/test/out_record_modifier.rb
CHANGED
@@ -48,4 +48,35 @@ class RecordModifierOutputTest < Test::Unit::TestCase
|
|
48
48
|
{"a" => 2}.merge(mapped),
|
49
49
|
], d.records
|
50
50
|
end
|
51
|
+
|
52
|
+
def test_set_char_encoding
|
53
|
+
d = create_driver %[
|
54
|
+
type record_modifier
|
55
|
+
|
56
|
+
tag foo.filtered
|
57
|
+
char_encoding utf-8
|
58
|
+
]
|
59
|
+
|
60
|
+
|
61
|
+
d.run do
|
62
|
+
d.emit("k" => 'v'.force_encoding('BINARY'))
|
63
|
+
end
|
64
|
+
|
65
|
+
assert_equal [{"k" => 'v'.force_encoding('UTF-8')}], d.records
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_convert_char_encoding
|
69
|
+
d = create_driver %[
|
70
|
+
type record_modifier
|
71
|
+
|
72
|
+
tag foo.filtered
|
73
|
+
char_encoding utf-8:cp932
|
74
|
+
]
|
75
|
+
|
76
|
+
d.run do
|
77
|
+
d.emit("k" => 'v'.force_encoding('utf-8'))
|
78
|
+
end
|
79
|
+
|
80
|
+
assert_equal [{"k" => 'v'.force_encoding('cp932')}], d.records
|
81
|
+
end
|
51
82
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-record-modifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -65,6 +65,7 @@ executables: []
|
|
65
65
|
extensions: []
|
66
66
|
extra_rdoc_files: []
|
67
67
|
files:
|
68
|
+
- .travis.yml
|
68
69
|
- ChangeLog
|
69
70
|
- Gemfile
|
70
71
|
- README.md
|
@@ -87,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
88
|
version: '0'
|
88
89
|
segments:
|
89
90
|
- 0
|
90
|
-
hash:
|
91
|
+
hash: -3676841215308348521
|
91
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
93
|
none: false
|
93
94
|
requirements:
|
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
97
|
version: '0'
|
97
98
|
segments:
|
98
99
|
- 0
|
99
|
-
hash:
|
100
|
+
hash: -3676841215308348521
|
100
101
|
requirements: []
|
101
102
|
rubyforge_project:
|
102
103
|
rubygems_version: 1.8.23
|