Module: MysqlImport::Logging

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

Instance Method Summary collapse

Instance Method Details

#import(*filters) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mysql_import/logger.rb', line 28

def import(*filters)
  super
ensure
  @logger.info('Imported tables:')
  if @result.imported.size > 0
    max_len = @result.imported.map(&:first).max_by{|w| w.length}.length
    @result.imported.sort.each do |t|
      space = ' ' * ((max_len - t[0].length) + 1)
      exec = t[1] ? format('%.3fs', t[1]) : 'FAILED'
      msg = "  #{t[0]}#{space}[exec:#{exec}"
      msg << " lock:#{format('%.3fs', t[2])}" if t[2]
      msg << ']'
      @logger.info(msg)
    end
  else
    @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 = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/mysql_import/logger.rb', line 17

def initialize(config, opts = {})
  @debug = opts.fetch(:debug, false)
  @logger = if opts[:log].is_a?(::Logger)
              opts[:log]
            else
              Logger.new(opts[:log], @debug)
            end
  embed_logger
  super
end