Class: LogStash::PluginMixins::Jdbc::CheckedCountLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ CheckedCountLogger

Returns a new instance of CheckedCountLogger.



5
6
7
8
9
10
# File 'lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb', line 5

def initialize(logger)
  @logger = logger
  @needs_check = true
  @count_is_supported = false
  @in_debug = @logger.debug?
end

Instance Method Details

#check_count_query(query) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb', line 27

def check_count_query(query)
  @needs_check = false
  begin
    execute_count(query)
    @count_is_supported = true
  rescue Exception => e
    @logger.warn("Attempting a count query raised an error, the generated count statement is most likely incorrect but check networking, authentication or your statement syntax", "exception" => e.message)
    @logger.warn("Ongoing count statement generation is being prevented")
    @count_is_supported = false
  end
end

#disable_countObject



12
13
14
15
# File 'lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb', line 12

def disable_count
  @needs_check = false
  @count_is_supported = false
end

#execute_count(query) ⇒ Object



39
40
41
# File 'lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb', line 39

def execute_count(query)
  query.count
end

#log_statement_parameters(statement, parameters, query) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/logstash/plugin_mixins/jdbc/checked_count_logger.rb', line 17

def log_statement_parameters(statement, parameters, query)
  return unless @in_debug
  check_count_query(query) if @needs_check && query
  if @count_is_supported
    @logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters, :count => execute_count(query))
  else
    @logger.debug("Executing JDBC query", :statement => statement, :parameters => parameters)
  end
end