From 199cc7b363b9d988c5f4e046da00942e3b27776f Mon Sep 17 00:00:00 2001 From: Ry Biesemeyer Date: Thu, 19 Jul 2018 23:12:05 +0000 Subject: [PATCH] connect our logger up to the charset converters The `LogStash::Util::Charset` utility will attempt to send a `warn` to its `@logger` instance variable when it encounters invalid encoding, but does not take a logger to its constructor. Failing to wire up a logger means that each time we attempt to convert a string and fail to arrive at valid UTF-8, we send `warn` to `NilClass`, which raises a `NoMethodError`. --- lib/logstash/inputs/jdbc.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/logstash/inputs/jdbc.rb b/lib/logstash/inputs/jdbc.rb index b50a2ba..47887a8 100755 --- a/lib/logstash/inputs/jdbc.rb +++ b/lib/logstash/inputs/jdbc.rb @@ -230,11 +230,14 @@ def register @jdbc_password = LogStash::Util::Password.new(File.read(@jdbc_password_filepath).strip) if @jdbc_password_filepath if enable_encoding? - @converters = {} - @columns_charset.each do |column_name, encoding| - @converters[encoding] = LogStash::Util::Charset.new(encoding) + encodings = @columns_charset.values + encodings << @charset if @charset + + @converters = encodings.each_with_object({}) do |encoding, converters| + converter = LogStash::Util::Charset.new(encoding) + converter.logger = self.logger + converters[encoding] = converter end - @converters[@charset] = LogStash::Util::Charset.new(@charset) if @charset end end # def register