Merge pull request #96 from mlkmhd/master
Adding more sql exception detail in log
This commit is contained in:
		
						commit
						079c3a6c78
					
				@ -201,21 +201,23 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
 | 
				
			|||||||
    begin
 | 
					    begin
 | 
				
			||||||
      connection = @pool.getConnection
 | 
					      connection = @pool.getConnection
 | 
				
			||||||
    rescue => e
 | 
					    rescue => e
 | 
				
			||||||
      log_jdbc_exception(e, true)
 | 
					      log_jdbc_exception(e, true, nil)
 | 
				
			||||||
      # If a connection is not available, then the server has gone away
 | 
					      # If a connection is not available, then the server has gone away
 | 
				
			||||||
      # We're not counting that towards our retry count.
 | 
					      # We're not counting that towards our retry count.
 | 
				
			||||||
      return events, false
 | 
					      return events, false
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    events.each do |event|
 | 
					    events.each do |event|
 | 
				
			||||||
 | 
					      query = nil
 | 
				
			||||||
      begin
 | 
					      begin
 | 
				
			||||||
        statement = connection.prepareStatement(
 | 
					        statement = connection.prepareStatement(
 | 
				
			||||||
          (@unsafe_statement == true) ? event.sprintf(@statement[0]) : @statement[0]
 | 
					          (@unsafe_statement == true) ? event.sprintf(@statement[0]) : @statement[0]
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        statement = add_statement_event_params(statement, event) if @statement.length > 1
 | 
					        statement = add_statement_event_params(statement, event) if @statement.length > 1
 | 
				
			||||||
 | 
					        query = statement.toString
 | 
				
			||||||
        statement.execute
 | 
					        statement.execute
 | 
				
			||||||
      rescue => e
 | 
					      rescue => e
 | 
				
			||||||
        if retry_exception?(e)
 | 
					        if retry_exception?(e, query)
 | 
				
			||||||
          events_to_retry.push(event)
 | 
					          events_to_retry.push(event)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      ensure
 | 
					      ensure
 | 
				
			||||||
@ -306,16 +308,16 @@ class LogStash::Outputs::Jdbc < LogStash::Outputs::Base
 | 
				
			|||||||
    statement
 | 
					    statement
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def retry_exception?(exception)
 | 
					  def retry_exception?(exception, query)
 | 
				
			||||||
    retrying = (exception.respond_to? 'getSQLState' and (RETRYABLE_SQLSTATE_CLASSES.include?(exception.getSQLState.to_s[0,2]) or @retry_sql_states.include?(exception.getSQLState)))
 | 
					    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)
 | 
					    log_jdbc_exception(exception, retrying, query)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    retrying
 | 
					    retrying
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def log_jdbc_exception(exception, retrying)
 | 
					  def log_jdbc_exception(exception, retrying, query)
 | 
				
			||||||
    current_exception = exception
 | 
					    current_exception = exception
 | 
				
			||||||
    log_text = 'JDBC - Exception. ' + (retrying ? 'Retrying' : 'Not retrying') + '.'
 | 
					    log_text = 'JDBC - Exception. ' + (retrying ? 'Retrying' : 'Not retrying') + '.' + ' with query: "' + query + '".'
 | 
				
			||||||
    log_method = (retrying ? 'warn' : 'error')
 | 
					    log_method = (retrying ? 'warn' : 'error')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    loop do
 | 
					    loop do
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user