From daebe44f3200391a4102749cda7a590ea437eceb Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 23 Oct 2017 11:24:28 +0330 Subject: [PATCH] add event in jdbc exception log instead of statement query. because some jdbc drivers (like oracle jdbc) not implemented toString() method in PreparedStatement class and it print java object hashcode instead of actual query. but in some jdbc implemention like postgresql and mysql and ... this has no problem --- lib/logstash/outputs/jdbc.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/logstash/outputs/jdbc.rb b/lib/logstash/outputs/jdbc.rb index f336eba..49a666a 100644 --- a/lib/logstash/outputs/jdbc.rb +++ b/lib/logstash/outputs/jdbc.rb @@ -208,16 +208,14 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base end events.each do |event| - query = nil begin statement = connection.prepareStatement( (@unsafe_statement == true) ? event.sprintf(@statement[0]) : @statement[0] ) statement = add_statement_event_params(statement, event) if @statement.length > 1 - query = statement.toString statement.execute rescue => e - if retry_exception?(e, query) + if retry_exception?(e, event.to_json()) events_to_retry.push(event) end ensure @@ -308,16 +306,21 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base statement end - def retry_exception?(exception, query) + def retry_exception?(exception, event) retrying = (exception.respond_to? 'getSQLState' and (RETRYABLE_SQLSTATE_CLASSES.include?(exception.getSQLState.to_s[0,2]) or @retry_sql_states.include?(exception.getSQLState))) - log_jdbc_exception(exception, retrying, query) + log_jdbc_exception(exception, retrying, event) retrying end - def log_jdbc_exception(exception, retrying, query) + def log_jdbc_exception(exception, retrying, event) current_exception = exception - log_text = 'JDBC - Exception. ' + (retrying ? 'Retrying' : 'Not retrying') + '.' + ' with query: "' + query + '".' + log_text = 'JDBC - Exception. ' + (retrying ? 'Retrying' : 'Not retrying') + '.' + + if(event != nil) + log_text += ' event: "' + event + '".' + end + log_method = (retrying ? 'warn' : 'error') loop do