fluent-mixin-plaintextformatter 0.2.3 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3f892bb7a90ccd8e91cae4e9581ac540b1365c4
4
- data.tar.gz: 04b6d2744aa25081c5e8e6b7f629f0b4d60fa9de
3
+ metadata.gz: 8a8f706410fb735c2cf645b5a11eb1b67f6afc82
4
+ data.tar.gz: dc8832c1ab304abe876300f83a367fd7201ed216
5
5
  SHA512:
6
- metadata.gz: 6a5b50af5b252f1b30c292cab814b501ca84656f3dc802cb5eed660973ade3bf1351e44ddc457071b004470c21b5f0e0823be0e4cdb40d91a0625c9908fe3b19
7
- data.tar.gz: e6c183f7a11465843e1aa4fc291f572ee03ef839bcae67e2240c011f080e989fc67b296261365289efa894ef121610b92b0e036bb293510e646e0aaff0d1096b
6
+ metadata.gz: 8b18fcd7738dd940b2d297e9b5e8802e20653bc4eaa189801af644c39361b1aa32bcfc430ddd93746a7c2a0cb0afbcff6bd9b3f1c2978fb384ee7295351c6df2
7
+ data.tar.gz: 9ee257ee3a95d62953e8e343139bc4634d9c91e6ab0ccc0b84f28a9c53568d5f54c28f4f129efb2515f35e45e9221b823b0e985d4f492ef0f24ec75c0ac4657a
@@ -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.3"
4
+ gem.version = "0.2.4"
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}
@@ -8,6 +8,8 @@ module Fluent
8
8
  attr_accessor :add_newline, :field_separator
9
9
  attr_accessor :remove_prefix, :default_tag
10
10
 
11
+ attr_accessor :suppress_log_broken_string
12
+
11
13
  attr_accessor :f_separator
12
14
 
13
15
  def first_value(*args)
@@ -65,6 +67,12 @@ module Fluent
65
67
  else
66
68
  raise Fluent::ConfigError, "invalid output_data_type:'#{@output_data_type}'"
67
69
  end
70
+
71
+ @suppress_log_broken_string = first_value(
72
+ Fluent::Config.bool_value(conf['suppress_log_broken_string']),
73
+ @suppress_log_broken_string,
74
+ false
75
+ )
68
76
  end
69
77
 
70
78
  def stringify_record(record)
@@ -105,11 +113,15 @@ module Fluent
105
113
  rescue JSON::GeneratorError => e
106
114
  # partial character in source, but hit end
107
115
  # source sequence is illegal/malformed utf-8
108
- $log.error e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
116
+ unless @suppress_log_broken_string
117
+ $log.warn e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
118
+ end
109
119
  ''
110
120
  rescue ArgumentError => e
111
121
  raise unless e.message == 'invalid byte sequence in UTF-8'
112
- $log.error e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
122
+ unless @suppress_log_broken_string
123
+ $log.warn e.message + ", ignored", :error_class => e.class, :tag => tag, :record => record.inspect # quote explicitly
124
+ end
113
125
  ''
114
126
  end
115
127
  end
@@ -16,8 +16,11 @@ require 'fluent/test'
16
16
  unless ENV.has_key?('VERBOSE')
17
17
  nulllogger = Object.new
18
18
  nulllogger.instance_eval {|obj|
19
+ def logs ; @logs ; end
20
+ def clear ; @logs = [] ; end
19
21
  def method_missing(method, *args)
20
- # pass
22
+ @logs ||= []
23
+ @logs.push([method, *args])
21
24
  end
22
25
  }
23
26
  $log = nulllogger
@@ -175,6 +175,47 @@ field_separator comma
175
175
  end
176
176
 
177
177
  def test_format_invalid_utf8_sequence
178
+ $log.clear
179
+
180
+ invalid_str = [0xFA, 0xFB].pack('CC').force_encoding('utf-8')
181
+ valid_str = [0xFF, 0xE3].pack("U*")
182
+
183
+ p1 = create_plugin_instance(Fluent::TestAOutput, %[
184
+ type testa
185
+ output_include_time true
186
+ output_include_tag true
187
+ output_data_type json
188
+ ])
189
+ r1 = p1.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
190
+ # #format should logs for this record (but we cannot test it...)
191
+ assert_equal '', r1
192
+
193
+ assert_equal :warn, $log.logs[0][0]
194
+ assert $log.logs[0][1] =~ /source sequence is illegal\/malformed utf-8, ignored/
195
+ assert_equal 'JSON::GeneratorError', $log.logs[0][2][:error_class].to_s
196
+
197
+ $log.clear
198
+
199
+ p2 = create_plugin_instance(Fluent::TestAOutput, %[
200
+ type testa
201
+ output_include_time true
202
+ output_include_tag true
203
+ output_data_type ltsv
204
+ ])
205
+ r2 = p2.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
206
+ # #format should logs for this record (but we cannot test it...)
207
+ assert_equal '', r2
208
+
209
+ assert_equal :warn, $log.logs[0][0]
210
+ assert $log.logs[0][1] =~ /^invalid byte sequence in UTF-8, ignored/
211
+ assert_equal 'ArgumentError', $log.logs[0][2][:error_class].to_s
212
+
213
+ $log.clear
214
+ end
215
+
216
+ def test_format_invalid_utf8_sequence_suppress_logs
217
+ $log.clear
218
+
178
219
  invalid_str = [0xFA, 0xFB].pack('CC').force_encoding('utf-8')
179
220
  valid_str = [0xFF, 0xE3].pack("U*")
180
221
 
@@ -183,20 +224,30 @@ type testa
183
224
  output_include_time true
184
225
  output_include_tag true
185
226
  output_data_type json
227
+ suppress_log_broken_string true
186
228
  ])
187
229
  r1 = p1.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
188
230
  # #format should logs for this record (but we cannot test it...)
189
231
  assert_equal '', r1
190
232
 
233
+ assert_equal 0, $log.logs.size
234
+
235
+ $log.clear
236
+
191
237
  p2 = create_plugin_instance(Fluent::TestAOutput, %[
192
238
  type testa
193
239
  output_include_time true
194
240
  output_include_tag true
195
241
  output_data_type ltsv
242
+ suppress_log_broken_string true
196
243
  ])
197
244
  r2 = p2.format('tag', Fluent::Engine.now, {'foo' => valid_str, 'bar' => invalid_str + valid_str})
198
245
  # #format should logs for this record (but we cannot test it...)
199
246
  assert_equal '', r2
247
+
248
+ assert_equal 0, $log.logs.size
249
+
250
+ $log.clear
200
251
  end
201
252
 
202
253
  def test_field_separator_newline_ltsv
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-mixin-plaintextformatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-30 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd