Module: WordpressDeploy::Logger

Defined in:
lib/wordpress_deploy/logger.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.verboseObject

Returns the value of attribute verbose.



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

def verbose
  @verbose
end

Class Method Details

.clear!Object



64
65
66
67
# File 'lib/wordpress_deploy/logger.rb', line 64

def clear!
  messages.clear
  @has_warnings = false
end

.debug(string, color = nil) ⇒ Object

Outputs a debug message to the console and writes it to the backup.log



21
22
23
24
25
# File 'lib/wordpress_deploy/logger.rb', line 21

def debug(string, color = nil)
  string = string.colorize(color) unless color.nil?
  to_console  loggify(string, :debug, :blue) if verbose
  to_file     loggify(string, :debug)
end

.error(string, color = nil) ⇒ Object

Outputs an error to the console and writes it to the backup.log Called when an Exception has caused the backup process to abort.



40
41
42
43
44
# File 'lib/wordpress_deploy/logger.rb', line 40

def error(string, color = nil)
  string = string.colorize(color) unless color.nil?
  to_console  loggify(string, :error,   :red), true
  to_file     loggify(string, :error)
end

.has_warnings?Boolean

Returns true if any warnings have been issued

Returns:

  • (Boolean)


60
61
62
# File 'lib/wordpress_deploy/logger.rb', line 60

def has_warnings?
  @has_warnings ||= false
end

.messagesObject

Returns an Array of all messages written to the log file for this session



54
55
56
# File 'lib/wordpress_deploy/logger.rb', line 54

def messages
  @messages ||= []
end

.normal(string, color = nil) ⇒ Object

Outputs the data as if it were a regular ‘puts’ command, but also logs it to the backup.log



12
13
14
15
16
# File 'lib/wordpress_deploy/logger.rb', line 12

def normal(string, color = nil)
  string = string.colorize(color) unless color.nil?
  to_console  loggify(string)
  to_file     loggify(string)
end

.silent(string) ⇒ Object

Silently logs data to the log file



48
49
50
# File 'lib/wordpress_deploy/logger.rb', line 48

def silent(string)
  to_file     loggify(string, :silent)
end

.truncate!(max_bytes = 500_000) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/wordpress_deploy/logger.rb', line 69

def truncate!(max_bytes = 500_000)
  log_file = Config.log_file
  return unless File.exist?(log_file)

  if File.stat(log_file).size > max_bytes
    FileUtils.mv(log_file, log_file + '~')
    File.open(log_file + '~', 'r') do |io_in|
      File.open(log_file, 'w') do |io_out|
        io_in.seek(-max_bytes, IO::SEEK_END) && io_in.gets
        while line = io_in.gets
          io_out.puts line
        end
      end
    end
    FileUtils.rm_f(log_file + '~')
  end
end

.warn(string, color = nil) ⇒ Object

Outputs a notice to the console and writes it to the backup.log Sets #has_warnings? true so :on_warning notifications will be sent



30
31
32
33
34
35
# File 'lib/wordpress_deploy/logger.rb', line 30

def warn(string, color = nil)
  @has_warnings = true
  string = string.colorize(color) unless color.nil?
  to_console  loggify(string, :warning, :yellow), true
  to_file     loggify(string, :warning)
end