Class: PerconaMigrator::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/percona_migrator/logger.rb

Overview

Copies the ActiveRecord::Migration #say and #write plus a new #write_no_newline to log the migration’s status. It’s not possible to reuse the from ActiveRecord::Migration because the migration’s instance can’t be seen from the connection adapter.

Instance Method Summary collapse

Constructor Details

#initialize(sanitizers) ⇒ Logger

Returns a new instance of Logger.



8
9
10
# File 'lib/percona_migrator/logger.rb', line 8

def initialize(sanitizers)
  @sanitizers = sanitizers
end

Instance Method Details

#say(message, subitem = false) ⇒ Object

Outputs the message through the stdout, following the ActiveRecord::Migration log format

Parameters:

  • message (String)
  • subitem (Boolean) (defaults to: false)

    whether to show message as a nested log item



17
18
19
# File 'lib/percona_migrator/logger.rb', line 17

def say(message, subitem = false)
  write "#{subitem ? "   ->" : "--"} #{message}"
end

#write(text = '') ⇒ Object

Outputs the text through the stdout adding a new line at the end

Parameters:

  • text (String) (defaults to: '')


24
25
26
# File 'lib/percona_migrator/logger.rb', line 24

def write(text = '')
  puts(sanitize(text))
end

#write_no_newline(text) ⇒ Object

Outputs the text through the stdout without adding a new line at the end

Parameters:

  • text (String)


31
32
33
# File 'lib/percona_migrator/logger.rb', line 31

def write_no_newline(text)
  print(sanitize(text))
end