Class: Mysqlcollector::Log

Inherits:
Object show all
Defined in:
lib/mysqlcollector/log.rb

Instance Method Summary collapse

Constructor Details

#initializeLog

Returns a new instance of Log.



5
6
7
# File 'lib/mysqlcollector/log.rb', line 5

def initialize
  @log = Logger.new(STDOUT)
end

Instance Method Details

#debug(command) ⇒ Object



16
17
18
19
20
# File 'lib/mysqlcollector/log.rb', line 16

def debug(command)
  return false unless valid?(command)

  @log.debug("#{command}") if $config[:debug]
end

#error(error) ⇒ Object



22
23
24
25
26
27
# File 'lib/mysqlcollector/log.rb', line 22

def error(error)
  return false unless valid?(error)

  @log.error(error)
  exit 1
end

#sql_error(error, sql) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/mysqlcollector/log.rb', line 29

def sql_error(error, sql)
  return false unless valid?(error)
  return false unless valid?(sql)

  @log.error("MySQL Error: #{error}")
  @log.error("MySQL SQL Statement: #{sql}")
  exit 1
end

#valid?(command) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/mysqlcollector/log.rb', line 9

def valid?(command)
  return false if command.nil?
  return false if command.empty?
  return false unless command.is_a?(String)
  true
end