fluent-mixin-plaintextformatter 0.2.0 → 0.2.1
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.
- data/README.md +1 -0
- data/fluent-mixin-plaintextformatter.gemspec +3 -1
- data/lib/fluent/mixin/plaintextformatter.rb +9 -1
- data/test/mixin/test_plaintextformatter.rb +14 -0
- data/test/output.rb +17 -0
- metadata +34 -2
data/README.md
CHANGED
@@ -71,6 +71,7 @@ Provided configurations are below:
|
|
71
71
|
* output\_include\_tag [yes/no]
|
72
72
|
* output\_data\_type
|
73
73
|
* 'json': output by JSON
|
74
|
+
* 'ltsv': output by LTSV, see: http://ltsv.org/
|
74
75
|
* 'attr:key1,key2,key3': values of 'key1' and 'key2' and ..., with separator specified by 'field_separator'
|
75
76
|
* field\_separator [TAB/SPACE/COMMA/SOH]
|
76
77
|
* add_newline [yes/no]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
Gem::Specification.new do |gem|
|
3
3
|
gem.name = "fluent-mixin-plaintextformatter"
|
4
|
-
gem.version = "0.2.
|
4
|
+
gem.version = "0.2.1"
|
5
5
|
gem.authors = ["TAGOMORI Satoshi"]
|
6
6
|
gem.email = ["tagomoris@gmail.com"]
|
7
7
|
gem.description = %q{included to format values into json, tsv or csv}
|
@@ -14,5 +14,7 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
|
16
16
|
gem.add_development_dependency "fluentd"
|
17
|
+
gem.add_development_dependency "ltsv"
|
17
18
|
gem.add_runtime_dependency "fluentd"
|
19
|
+
gem.add_runtime_dependency "ltsv"
|
18
20
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fluent/config'
|
2
|
+
require 'ltsv'
|
2
3
|
|
3
4
|
module Fluent
|
4
5
|
module Mixin
|
@@ -57,6 +58,8 @@ module Fluent
|
|
57
58
|
|
58
59
|
@custom_attributes = if @output_data_type == 'json'
|
59
60
|
nil
|
61
|
+
elsif @output_data_type == 'ltsv'
|
62
|
+
nil
|
60
63
|
elsif @output_data_type =~ /^attr:(.+)$/
|
61
64
|
$1.split(',')
|
62
65
|
else
|
@@ -66,7 +69,12 @@ module Fluent
|
|
66
69
|
|
67
70
|
def stringify_record(record)
|
68
71
|
if @custom_attributes.nil?
|
69
|
-
|
72
|
+
case @output_data_type
|
73
|
+
when 'json'
|
74
|
+
record.to_json
|
75
|
+
when 'ltsv'
|
76
|
+
LTSV.dump(record)
|
77
|
+
end
|
70
78
|
else
|
71
79
|
@custom_attributes.map{|attr|
|
72
80
|
(record[attr] || 'NULL').to_s
|
@@ -173,4 +173,18 @@ field_separator comma
|
|
173
173
|
# format
|
174
174
|
assert_equal "10000,foo foo baz\n", p.format('test.a', 1342163105, r)
|
175
175
|
end
|
176
|
+
|
177
|
+
def test_field_separator_newline_ltsv
|
178
|
+
p = create_plugin_instance(Fluent::TestDOutput, "type testd\nlocaltime\n")
|
179
|
+
r = {'foo' => 'foo foo baz', 'bar' => 10000}
|
180
|
+
rs = {:foo => 'foo foo baz', :bar => "10000"}
|
181
|
+
# stringify
|
182
|
+
assert_equal rs, LTSV.parse(p.stringify_record(r))
|
183
|
+
|
184
|
+
line = p.format('test.d', 1342163105, r)
|
185
|
+
# output_include_time true, output_include_tag true, localtime, separator COMMA
|
186
|
+
assert_equal ['2012-07-13T16:05:05+09:00', 'test.d'], line.chomp.split(/\t/, 3)[0..1]
|
187
|
+
# output_data_type json
|
188
|
+
assert_equal rs, LTSV.parse(line.chomp.split(/\t/, 3)[2])
|
189
|
+
end
|
176
190
|
end
|
data/test/output.rb
CHANGED
@@ -61,4 +61,21 @@ module Fluent
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
class TestDOutput < Fluent::BufferedOutput
|
65
|
+
Fluent::Plugin.register_output('testa', self)
|
66
|
+
|
67
|
+
config_set_default :buffer_type, 'memory'
|
68
|
+
|
69
|
+
include Fluent::Mixin::PlainTextFormatter
|
70
|
+
|
71
|
+
config_set_default :output_include_time, true
|
72
|
+
config_set_default :output_include_tag, true
|
73
|
+
config_set_default :output_data_type, 'ltsv'
|
74
|
+
config_set_default :remove_prefix, nil
|
75
|
+
config_set_default :default_tag, 'tag.blank'
|
76
|
+
|
77
|
+
def configure(conf)
|
78
|
+
super
|
79
|
+
end
|
80
|
+
end
|
64
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-mixin-plaintextformatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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-02-
|
12
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fluentd
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: ltsv
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: fluentd
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +59,22 @@ dependencies:
|
|
43
59
|
- - ! '>='
|
44
60
|
- !ruby/object:Gem::Version
|
45
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: ltsv
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
46
78
|
description: included to format values into json, tsv or csv
|
47
79
|
email:
|
48
80
|
- tagomoris@gmail.com
|