fluentd 1.11.3-x86-mingw32 → 1.12.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of fluentd might be problematic. Click here for more details.

Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.deepsource.toml +13 -0
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
  4. data/.github/ISSUE_TEMPLATE/config.yml +5 -0
  5. data/.github/workflows/linux-test.yaml +36 -0
  6. data/.github/workflows/macos-test.yaml +30 -0
  7. data/.github/workflows/stale-actions.yml +22 -0
  8. data/.github/workflows/windows-test.yaml +30 -0
  9. data/CHANGELOG.md +138 -0
  10. data/MAINTAINERS.md +5 -2
  11. data/README.md +2 -2
  12. data/bin/fluent-cap-ctl +7 -0
  13. data/bin/fluent-ctl +7 -0
  14. data/fluentd.gemspec +4 -3
  15. data/lib/fluent/capability.rb +87 -0
  16. data/lib/fluent/command/bundler_injection.rb +1 -1
  17. data/lib/fluent/command/ca_generate.rb +6 -3
  18. data/lib/fluent/command/cap_ctl.rb +174 -0
  19. data/lib/fluent/command/cat.rb +0 -1
  20. data/lib/fluent/command/ctl.rb +177 -0
  21. data/lib/fluent/command/fluentd.rb +4 -0
  22. data/lib/fluent/command/plugin_config_formatter.rb +18 -2
  23. data/lib/fluent/compat/parser.rb +2 -2
  24. data/lib/fluent/config/section.rb +2 -2
  25. data/lib/fluent/config/types.rb +2 -2
  26. data/lib/fluent/env.rb +4 -0
  27. data/lib/fluent/event.rb +3 -13
  28. data/lib/fluent/load.rb +0 -1
  29. data/lib/fluent/plugin.rb +5 -0
  30. data/lib/fluent/plugin/buffer.rb +2 -21
  31. data/lib/fluent/plugin/formatter.rb +24 -0
  32. data/lib/fluent/plugin/formatter_csv.rb +1 -1
  33. data/lib/fluent/plugin/formatter_hash.rb +3 -1
  34. data/lib/fluent/plugin/formatter_json.rb +3 -1
  35. data/lib/fluent/plugin/formatter_ltsv.rb +7 -5
  36. data/lib/fluent/plugin/formatter_out_file.rb +6 -4
  37. data/lib/fluent/plugin/formatter_single_value.rb +4 -2
  38. data/lib/fluent/plugin/formatter_tsv.rb +4 -2
  39. data/lib/fluent/plugin/in_http.rb +24 -3
  40. data/lib/fluent/plugin/in_monitor_agent.rb +1 -1
  41. data/lib/fluent/plugin/in_tail.rb +128 -41
  42. data/lib/fluent/plugin/in_tail/position_file.rb +39 -14
  43. data/lib/fluent/plugin/in_tcp.rb +1 -0
  44. data/lib/fluent/plugin/out_copy.rb +18 -5
  45. data/lib/fluent/plugin/out_exec_filter.rb +3 -3
  46. data/lib/fluent/plugin/out_forward.rb +61 -28
  47. data/lib/fluent/plugin/out_http.rb +29 -4
  48. data/lib/fluent/plugin/output.rb +14 -6
  49. data/lib/fluent/plugin/storage_local.rb +3 -3
  50. data/lib/fluent/plugin_helper/http_server/compat/server.rb +1 -1
  51. data/lib/fluent/plugin_helper/inject.rb +4 -1
  52. data/lib/fluent/plugin_helper/retry_state.rb +4 -0
  53. data/lib/fluent/supervisor.rb +153 -48
  54. data/lib/fluent/system_config.rb +2 -1
  55. data/lib/fluent/time.rb +58 -1
  56. data/lib/fluent/version.rb +1 -1
  57. data/lib/fluent/winsvc.rb +22 -4
  58. data/templates/plugin_config_formatter/param.md-table.erb +10 -0
  59. data/test/command/test_binlog_reader.rb +22 -6
  60. data/test/command/test_cap_ctl.rb +100 -0
  61. data/test/command/test_ctl.rb +57 -0
  62. data/test/command/test_fluentd.rb +38 -0
  63. data/test/command/test_plugin_config_formatter.rb +124 -2
  64. data/test/config/test_configurable.rb +1 -1
  65. data/test/plugin/in_tail/test_position_file.rb +46 -26
  66. data/test/plugin/out_forward/test_connection_manager.rb +6 -0
  67. data/test/plugin/test_filter_stdout.rb +6 -1
  68. data/test/plugin/test_formatter_hash.rb +6 -3
  69. data/test/plugin/test_formatter_json.rb +14 -4
  70. data/test/plugin/test_formatter_ltsv.rb +13 -5
  71. data/test/plugin/test_formatter_out_file.rb +35 -14
  72. data/test/plugin/test_formatter_single_value.rb +12 -6
  73. data/test/plugin/test_formatter_tsv.rb +12 -4
  74. data/test/plugin/test_in_exec.rb +1 -1
  75. data/test/plugin/test_in_http.rb +25 -0
  76. data/test/plugin/test_in_tail.rb +470 -32
  77. data/test/plugin/test_out_copy.rb +87 -0
  78. data/test/plugin/test_out_file.rb +23 -18
  79. data/test/plugin/test_out_forward.rb +74 -0
  80. data/test/plugin/test_out_http.rb +20 -1
  81. data/test/plugin/test_output.rb +12 -0
  82. data/test/plugin/test_parser_syslog.rb +2 -2
  83. data/test/plugin/test_sd_file.rb +1 -1
  84. data/test/plugin_helper/test_child_process.rb +5 -2
  85. data/test/plugin_helper/test_compat_parameters.rb +7 -2
  86. data/test/plugin_helper/test_http_server_helper.rb +3 -1
  87. data/test/plugin_helper/test_inject.rb +42 -0
  88. data/test/plugin_helper/test_server.rb +18 -5
  89. data/test/test_capability.rb +74 -0
  90. data/test/test_event.rb +16 -0
  91. data/test/test_formatter.rb +64 -10
  92. data/test/test_output.rb +6 -1
  93. data/test/test_supervisor.rb +150 -1
  94. data/test/test_time_parser.rb +109 -0
  95. metadata +61 -29
  96. data/.travis.yml +0 -57
  97. data/appveyor.yml +0 -28
@@ -1453,7 +1453,7 @@ module Fluent::Config
1453
1453
  @example = ConfigurableSpec::ExampleWithSkipAccessor.new
1454
1454
  @example.configure(config_element('ROOT'))
1455
1455
  assert_equal 'example7', @example.instance_variable_get(:@name)
1456
- assert_raise NoMethodError.new("undefined method `name' for #{@example}") do
1456
+ assert_raise NoMethodError do
1457
1457
  @example.name
1458
1458
  end
1459
1459
  end
@@ -1,5 +1,6 @@
1
1
  require_relative '../../helper'
2
2
  require 'fluent/plugin/in_tail/position_file'
3
+ require 'fluent/plugin/in_tail'
3
4
 
4
5
  require 'fileutils'
5
6
  require 'tempfile'
@@ -27,9 +28,15 @@ class IntailPositionFileTest < Test::Unit::TestCase
27
28
  f.seek(0)
28
29
  end
29
30
 
31
+ def follow_inodes_block
32
+ [true, false].each do |follow_inodes|
33
+ yield follow_inodes
34
+ end
35
+ end
36
+
30
37
  test '.load' do
31
38
  write_data(@file, TEST_CONTENT)
32
- Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
39
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
33
40
 
34
41
  @file.seek(0)
35
42
  lines = @file.readlines
@@ -41,7 +48,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
41
48
  sub_test_case '#try_compact' do
42
49
  test 'compact invalid and convert 32 bit inode value' do
43
50
  write_data(@file, TEST_CONTENT)
44
- Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log).try_compact
51
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
45
52
 
46
53
  @file.seek(0)
47
54
  lines = @file.readlines
@@ -55,7 +62,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
55
62
  valid_path\t0000000000000002\t0000000000000001
56
63
  valid_path\t0000000000000003\t0000000000000004
57
64
  EOF
58
- Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log).try_compact
65
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).try_compact
59
66
 
60
67
  @file.seek(0)
61
68
  lines = @file.readlines
@@ -64,7 +71,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
64
71
 
65
72
  test 'does not change when the file is changed' do
66
73
  write_data(@file, TEST_CONTENT)
67
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log)
74
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
68
75
 
69
76
  mock.proxy(pf).fetch_compacted_entries do |r|
70
77
  @file.write("unwatched\t#{UNWATCHED_STR}\t0000000000000000\n")
@@ -78,12 +85,17 @@ class IntailPositionFileTest < Test::Unit::TestCase
78
85
  assert_equal 5, lines.size
79
86
  end
80
87
 
81
- test 'update seek postion of remained position entry' do
82
- pf = Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log)
83
- pf['path1']
84
- pf['path2']
85
- pf['path3']
86
- pf.unwatch('path1')
88
+ test 'update seek position of remained position entry' do
89
+ pf = Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log})
90
+ target_info1 = Fluent::Plugin::TailInput::TargetInfo.new('path1', -1)
91
+ target_info2 = Fluent::Plugin::TailInput::TargetInfo.new('path2', -1)
92
+ target_info3 = Fluent::Plugin::TailInput::TargetInfo.new('path3', -1)
93
+ pf[target_info1]
94
+ pf[target_info2]
95
+ pf[target_info3]
96
+
97
+ target_info1_2 = Fluent::Plugin::TailInput::TargetInfo.new('path1', 1234)
98
+ pf.unwatch(target_info1_2)
87
99
 
88
100
  pf.try_compact
89
101
 
@@ -93,8 +105,10 @@ class IntailPositionFileTest < Test::Unit::TestCase
93
105
  assert_equal "path3\t0000000000000000\t0000000000000000\n", lines[1]
94
106
  assert_equal 2, lines.size
95
107
 
96
- pf.unwatch('path2')
97
- pf.unwatch('path3')
108
+ target_info2_2 = Fluent::Plugin::TailInput::TargetInfo.new('path2', 1235)
109
+ target_info3_2 = Fluent::Plugin::TailInput::TargetInfo.new('path3', 1236)
110
+ pf.unwatch(target_info2_2)
111
+ pf.unwatch(target_info3_2)
98
112
  @file.seek(0)
99
113
  lines = @file.readlines
100
114
  assert_equal "path2\t#{UNWATCHED_STR}\t0000000000000000\n", lines[0]
@@ -106,7 +120,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
106
120
  sub_test_case '#load' do
107
121
  test 'compact invalid and convert 32 bit inode value' do
108
122
  write_data(@file, TEST_CONTENT)
109
- Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
123
+ Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
110
124
 
111
125
  @file.seek(0)
112
126
  lines = @file.readlines
@@ -120,7 +134,7 @@ class IntailPositionFileTest < Test::Unit::TestCase
120
134
  valid_path\t0000000000000002\t0000000000000001
121
135
  valid_path\t0000000000000003\t0000000000000004
122
136
  EOF
123
- Fluent::Plugin::TailInput::PositionFile.new(@file, logger: $log).load
137
+ Fluent::Plugin::TailInput::PositionFile.new(@file, false, {}, **{logger: $log}).load
124
138
 
125
139
  @file.seek(0)
126
140
  lines = @file.readlines
@@ -131,9 +145,10 @@ class IntailPositionFileTest < Test::Unit::TestCase
131
145
  sub_test_case '#[]' do
132
146
  test 'return entry' do
133
147
  write_data(@file, TEST_CONTENT)
134
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
148
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, **{logger: $log})
135
149
 
136
- f = pf['valid_path']
150
+ valid_target_info = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', File.stat(@file).ino)
151
+ f = pf[valid_target_info]
137
152
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, f.class
138
153
  assert_equal 2, f.read_pos
139
154
  assert_equal 1, f.read_inode
@@ -142,7 +157,8 @@ class IntailPositionFileTest < Test::Unit::TestCase
142
157
  lines = @file.readlines
143
158
  assert_equal 2, lines.size
144
159
 
145
- f = pf['nonexist_path']
160
+ nonexistent_target_info = Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)
161
+ f = pf[nonexistent_target_info]
146
162
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, f.class
147
163
  assert_equal 0, f.read_pos
148
164
  assert_equal 0, f.read_inode
@@ -155,19 +171,19 @@ class IntailPositionFileTest < Test::Unit::TestCase
155
171
 
156
172
  test 'does not change other value position if other entry try to write' do
157
173
  write_data(@file, TEST_CONTENT)
158
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
174
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, logger: $log)
159
175
 
160
- f = pf['nonexist_path']
176
+ f = pf[Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)]
161
177
  assert_equal 0, f.read_inode
162
178
  assert_equal 0, f.read_pos
163
179
 
164
- pf['valid_path'].update(1, 2)
180
+ pf[Fluent::Plugin::TailInput::TargetInfo.new('valid_path', File.stat(@file).ino)].update(1, 2)
165
181
 
166
- f = pf['nonexist_path']
182
+ f = pf[Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)]
167
183
  assert_equal 0, f.read_inode
168
184
  assert_equal 0, f.read_pos
169
185
 
170
- pf['nonexist_path'].update(1, 2)
186
+ pf[Fluent::Plugin::TailInput::TargetInfo.new('nonexist_path', -1)].update(1, 2)
171
187
  assert_equal 1, f.read_inode
172
188
  assert_equal 2, f.read_pos
173
189
  end
@@ -176,14 +192,18 @@ class IntailPositionFileTest < Test::Unit::TestCase
176
192
  sub_test_case '#unwatch' do
177
193
  test 'deletes entry by path' do
178
194
  write_data(@file, TEST_CONTENT)
179
- pf = Fluent::Plugin::TailInput::PositionFile.load(@file, logger: $log)
180
- p1 = pf['valid_path']
195
+ pf = Fluent::Plugin::TailInput::PositionFile.load(@file, false, {}, logger: $log)
196
+ inode1 = File.stat(@file).ino
197
+ target_info1 = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', inode1)
198
+ p1 = pf[target_info1]
181
199
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, p1.class
182
200
 
183
- pf.unwatch('valid_path')
201
+ pf.unwatch(target_info1)
184
202
  assert_equal p1.read_pos, Fluent::Plugin::TailInput::PositionFile::UNWATCHED_POSITION
185
203
 
186
- p2 = pf['valid_path']
204
+ inode2 = File.stat(@file).ino
205
+ target_info2 = Fluent::Plugin::TailInput::TargetInfo.new('valid_path', inode2)
206
+ p2 = pf[target_info2]
187
207
  assert_equal Fluent::Plugin::TailInput::FilePositionEntry, p2.class
188
208
 
189
209
  assert_not_equal p1, p2
@@ -81,6 +81,8 @@ class ConnectionManager < Test::Unit::TestCase
81
81
 
82
82
  sub_test_case 'when socket_cache exists' do
83
83
  test 'calls connect_keepalive' do
84
+ omit "Proxy of RR doesn't support kwargs of Ruby 3 yet" if RUBY_VERSION.split('.')[0].to_i >= 3
85
+
84
86
  cache = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
85
87
  mock(cache).checkin('sock').never
86
88
 
@@ -99,6 +101,8 @@ class ConnectionManager < Test::Unit::TestCase
99
101
  end
100
102
 
101
103
  test 'calls connect_keepalive and closes socket with block' do
104
+ omit "Proxy of RR doesn't support kwargs of Ruby 3 yet" if RUBY_VERSION.split('.')[0].to_i >= 3
105
+
102
106
  cache = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
103
107
  mock(cache).checkin('sock').once
104
108
 
@@ -118,6 +122,8 @@ class ConnectionManager < Test::Unit::TestCase
118
122
  end
119
123
 
120
124
  test 'does not call dec_ref when ack is passed' do
125
+ omit "Proxy of RR doesn't support kwargs of Ruby 3 yet" if RUBY_VERSION.split('.')[0].to_i >= 3
126
+
121
127
  cache = Fluent::Plugin::ForwardOutput::SocketCache.new(10, $log)
122
128
  mock(cache).checkin('sock').never
123
129
  sock = 'sock'
@@ -12,6 +12,11 @@ class StdoutFilterTest < Test::Unit::TestCase
12
12
  @old_tz = ENV["TZ"]
13
13
  ENV["TZ"] = "UTC"
14
14
  Timecop.freeze
15
+ @default_newline = if Fluent.windows?
16
+ "\r\n"
17
+ else
18
+ "\n"
19
+ end
15
20
  end
16
21
 
17
22
  def teardown
@@ -106,7 +111,7 @@ class StdoutFilterTest < Test::Unit::TestCase
106
111
  def test_format_json
107
112
  d = create_driver(CONFIG + config_element("", "", { "format" => "json" }))
108
113
  out = capture_log(d) { filter(d, event_time, {'test' => 'test'}) }
109
- assert_equal "{\"test\":\"test\"}\n", out
114
+ assert_equal "{\"test\":\"test\"}#{@default_newline}", out
110
115
  end
111
116
  end
112
117
 
@@ -19,11 +19,14 @@ class HashFormatterTest < ::Test::Unit::TestCase
19
19
  {'message' => 'awesome', 'greeting' => 'hello'}
20
20
  end
21
21
 
22
- def test_format
23
- d = create_driver({})
22
+ data("newline (LF)" => ["lf", "\n"],
23
+ "newline (CRLF)" => ["crlf", "\r\n"])
24
+ def test_format(data)
25
+ newline_conf, newline = data
26
+ d = create_driver({"newline" => newline_conf})
24
27
  formatted = d.instance.format(tag, @time, record)
25
28
 
26
- assert_equal(%Q!{"message"=>"awesome", "greeting"=>"hello"}\n!, formatted.encode(Encoding::UTF_8))
29
+ assert_equal(%Q!{"message"=>"awesome", "greeting"=>"hello"}#{newline}!, formatted.encode(Encoding::UTF_8))
27
30
  end
28
31
 
29
32
  def test_format_without_newline
@@ -7,6 +7,11 @@ class JsonFormatterTest < ::Test::Unit::TestCase
7
7
 
8
8
  def setup
9
9
  @time = event_time
10
+ @default_newline = if Fluent.windows?
11
+ "\r\n"
12
+ else
13
+ "\n"
14
+ end
10
15
  end
11
16
 
12
17
  def create_driver(conf = "")
@@ -25,12 +30,17 @@ class JsonFormatterTest < ::Test::Unit::TestCase
25
30
  {:message => :awesome}
26
31
  end
27
32
 
28
- data('oj' => 'oj', 'yajl' => 'yajl')
33
+ data('oj with LF' => ['oj', "lf", "\n"],
34
+ 'oj with CRLF' => ['oj', "crlf", "\r\n"],
35
+ 'yajl with LF' => ['yajl', "lf", "\n"],
36
+ 'yajl with CRLF' => ['yajl', "crlf", "\r\n"]
37
+ )
29
38
  def test_format(data)
30
- d = create_driver('json_parser' => data)
39
+ parser, newline_conf, newline = data
40
+ d = create_driver('json_parser' => parser, 'newline' => newline_conf)
31
41
  formatted = d.instance.format(tag, @time, record)
32
42
 
33
- assert_equal("#{JSON.generate(record)}\n", formatted)
43
+ assert_equal("#{JSON.generate(record)}#{newline}", formatted)
34
44
  end
35
45
 
36
46
  data('oj' => 'oj', 'yajl' => 'yajl')
@@ -46,6 +56,6 @@ class JsonFormatterTest < ::Test::Unit::TestCase
46
56
  d = create_driver('json_parser' => data)
47
57
  formatted = d.instance.format(tag, @time, symbolic_record)
48
58
 
49
- assert_equal("#{JSON.generate(record)}\n", formatted)
59
+ assert_equal("#{JSON.generate(record)}#{@default_newline}", formatted)
50
60
  end
51
61
  end
@@ -36,11 +36,14 @@ class LabeledTSVFormatterTest < ::Test::Unit::TestCase
36
36
  assert_equal false, d.instance.add_newline
37
37
  end
38
38
 
39
- def test_format
40
- d = create_driver({})
39
+ data("newline (LF)" => ["lf", "\n"],
40
+ "newline (CRLF)" => ["crlf", "\r\n"])
41
+ def test_format(data)
42
+ newline_conf, newline = data
43
+ d = create_driver({"newline" => newline_conf})
41
44
  formatted = d.instance.format(tag, @time, record)
42
45
 
43
- assert_equal("message:awesome\tgreeting:hello\n", formatted)
46
+ assert_equal("message:awesome\tgreeting:hello#{newline}", formatted)
44
47
  end
45
48
 
46
49
  def test_format_without_newline
@@ -50,13 +53,18 @@ class LabeledTSVFormatterTest < ::Test::Unit::TestCase
50
53
  assert_equal("message:awesome\tgreeting:hello", formatted)
51
54
  end
52
55
 
53
- def test_format_with_customized_delimiters
56
+ data("newline (LF)" => ["lf", "\n"],
57
+ "newline (CRLF)" => ["crlf", "\r\n"])
58
+ def test_format_with_customized_delimiters(data)
59
+ newline_conf, newline = data
60
+
54
61
  d = create_driver(
55
62
  'delimiter' => ',',
56
63
  'label_delimiter' => '=',
64
+ 'newline' => newline_conf,
57
65
  )
58
66
  formatted = d.instance.format(tag, @time, record)
59
67
 
60
- assert_equal("message=awesome,greeting=hello\n", formatted)
68
+ assert_equal("message=awesome,greeting=hello#{newline}", formatted)
61
69
  end
62
70
  end
@@ -5,6 +5,11 @@ require 'fluent/plugin/formatter_out_file'
5
5
  class OutFileFormatterTest < ::Test::Unit::TestCase
6
6
  def setup
7
7
  @time = event_time
8
+ @default_newline = if Fluent.windows?
9
+ "\r\n"
10
+ else
11
+ "\n"
12
+ end
8
13
  end
9
14
 
10
15
  def create_driver(conf = {})
@@ -48,48 +53,64 @@ class OutFileFormatterTest < ::Test::Unit::TestCase
48
53
  oldtz, ENV['TZ'] = ENV['TZ'], "UTC+07"
49
54
  d = create_driver(config_element('ROOT', '', {key => value}))
50
55
  tag = 'test'
51
- assert_equal "#{expected}\t#{tag}\t#{Yajl.dump(record)}\n", d.instance.format(tag, time, record)
56
+ assert_equal "#{expected}\t#{tag}\t#{Yajl.dump(record)}#{@default_newline}", d.instance.format(tag, time, record)
52
57
  ensure
53
58
  ENV['TZ'] = oldtz
54
59
  end
55
60
  end
56
61
 
57
- def test_format
58
- d = create_driver({})
62
+ data("newline (LF)" => ["lf", "\n"],
63
+ "newline (CRLF)" => ["crlf", "\r\n"])
64
+ def test_format(data)
65
+ newline_conf, newline = data
66
+ d = create_driver({"newline" => newline_conf})
59
67
  formatted = d.instance.format(tag, @time, record)
60
68
 
61
- assert_equal("#{time2str(@time)}\t#{tag}\t#{Yajl.dump(record)}\n", formatted)
69
+ assert_equal("#{time2str(@time)}\t#{tag}\t#{Yajl.dump(record)}#{newline}", formatted)
62
70
  end
63
71
 
64
- def test_format_without_time
65
- d = create_driver('output_time' => 'false')
72
+ data("newline (LF)" => ["lf", "\n"],
73
+ "newline (CRLF)" => ["crlf", "\r\n"])
74
+ def test_format_without_time(data)
75
+ newline_conf, newline = data
76
+ d = create_driver('output_time' => 'false', 'newline' => newline_conf)
66
77
  formatted = d.instance.format(tag, @time, record)
67
78
 
68
- assert_equal("#{tag}\t#{Yajl.dump(record)}\n", formatted)
79
+ assert_equal("#{tag}\t#{Yajl.dump(record)}#{newline}", formatted)
69
80
  end
70
81
 
71
- def test_format_without_tag
72
- d = create_driver('output_tag' => 'false')
82
+ data("newline (LF)" => ["lf", "\n"],
83
+ "newline (CRLF)" => ["crlf", "\r\n"])
84
+ def test_format_without_tag(data)
85
+ newline_conf, newline = data
86
+ d = create_driver('output_tag' => 'false', 'newline' => newline_conf)
73
87
  formatted = d.instance.format(tag, @time, record)
74
88
 
75
- assert_equal("#{time2str(@time)}\t#{Yajl.dump(record)}\n", formatted)
89
+ assert_equal("#{time2str(@time)}\t#{Yajl.dump(record)}#{newline}", formatted)
76
90
  end
77
91
 
92
+ data("newline (LF)" => ["lf", "\n"],
93
+ "newline (CRLF)" => ["crlf", "\r\n"])
78
94
  def test_format_without_time_and_tag
79
- d = create_driver('output_tag' => 'false', 'output_time' => 'false')
95
+ newline_conf, newline = data
96
+ d = create_driver('output_tag' => 'false', 'output_time' => 'false', 'newline' => newline_conf)
80
97
  formatted = d.instance.format('tag', @time, record)
81
98
 
82
- assert_equal("#{Yajl.dump(record)}\n", formatted)
99
+ assert_equal("#{Yajl.dump(record)}#{newline}", formatted)
83
100
  end
84
101
 
85
- def test_format_without_time_and_tag_against_string_literal_configure
102
+ data("newline (LF)" => ["lf", "\n"],
103
+ "newline (CRLF)" => ["crlf", "\r\n"])
104
+ def test_format_without_time_and_tag_against_string_literal_configure(data)
105
+ newline_conf, newline = data
86
106
  d = create_driver(%[
87
107
  utc true
88
108
  output_tag false
89
109
  output_time false
110
+ newline #{newline_conf}
90
111
  ])
91
112
  formatted = d.instance.format('tag', @time, record)
92
113
 
93
- assert_equal("#{Yajl.dump(record)}\n", formatted)
114
+ assert_equal("#{Yajl.dump(record)}#{newline}", formatted)
94
115
  end
95
116
  end
@@ -17,10 +17,13 @@ class SingleValueFormatterTest < ::Test::Unit::TestCase
17
17
  assert_equal "foobar", d.instance.message_key
18
18
  end
19
19
 
20
- def test_format
21
- d = create_driver
20
+ data("newline (LF)" => ["lf", "\n"],
21
+ "newline (CRLF)" => ["crlf", "\r\n"])
22
+ def test_format(data)
23
+ newline_conf, newline = data
24
+ d = create_driver('newline' => newline_conf)
22
25
  formatted = d.instance.format('tag', event_time, {'message' => 'awesome'})
23
- assert_equal("awesome\n", formatted)
26
+ assert_equal("awesome#{newline}", formatted)
24
27
  end
25
28
 
26
29
  def test_format_without_newline
@@ -29,10 +32,13 @@ class SingleValueFormatterTest < ::Test::Unit::TestCase
29
32
  assert_equal("awesome", formatted)
30
33
  end
31
34
 
32
- def test_format_with_message_key
33
- d = create_driver('message_key' => 'foobar')
35
+ data("newline (LF)" => ["lf", "\n"],
36
+ "newline (CRLF)" => ["crlf", "\r\n"])
37
+ def test_format_with_message_key(data)
38
+ newline_conf, newline = data
39
+ d = create_driver('message_key' => 'foobar', 'newline' => newline_conf)
34
40
  formatted = d.instance.format('tag', event_time, {'foobar' => 'foo'})
35
41
 
36
- assert_equal("foo\n", formatted)
42
+ assert_equal("foo#{newline}", formatted)
37
43
  end
38
44
  end