Module: MysqlImport::Logging

Included in:
MysqlImport
Defined in:
lib/mysql_import/logger.rb

Instance Method Summary collapse

Instance Method Details

#import(*filters) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mysql_import/logger.rb', line 39

def import(*filters)
  super
ensure
  logger.info('Imported tables:')
  if result.imported.size > 0
    result.imported.sort.each {|t| logger.info("  #{t[0]} (#{t[1]} sec)") }
  else
    result.logger.info('  nothing...')
  end
  if result.skipped.size > 0
    logger.info('Skipped tables:')
    result.skipped.sort.each {|t| logger.info("  #{t}") }
  end

  result.clear
end

#initialize(config, opts = {}, sql_opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/mysql_import/logger.rb', line 24

def initialize(config, opts ={}, sql_opts = {})
  @logger = Logger.new(opts[:log], opts.fetch(:debug, false))

  LoadDataInfile2::Client.class_exec(@logger) do |logger|
    define_method :build_sql_with_logging do |file, options|
      options = {} unless options
      build_sql_without_logging(file, options).tap {|sql| logger.debug("sql: #{sql}") }
    end
    alias_method :build_sql_without_logging, :build_sql
    alias_method :build_sql, :build_sql_with_logging
  end

  super
end