Class: EY::Backup::Logger
- Inherits:
-
Object
- Object
- EY::Backup::Logger
- Extended by:
- Forwardable
- Defined in:
- lib/ey_backup/logger.rb
Instance Attribute Summary collapse
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_alert?(db) ⇒ Boolean
- #debug(msg) ⇒ Object
- #error(msg, db = nil) ⇒ Object
- #exception(type, msg) ⇒ Object
- #info(msg) ⇒ Object
-
#initialize(stdout = $stdout, stderr = $stderr) ⇒ Logger
constructor
A new instance of Logger.
- #okay(db, size) ⇒ Object
- #push_dashboard_alert(message, alert_level, db = nil) ⇒ Object
- #say(msg, newline = true) ⇒ Object
- #set_alert(msg, db) ⇒ Object
- #set_log_path=(path) ⇒ Object
- #set_verbose ⇒ Object
- #verbose(msg) ⇒ Object
- #warn(msg, db = nil) ⇒ Object
Constructor Details
#initialize(stdout = $stdout, stderr = $stderr) ⇒ Logger
Returns a new instance of Logger.
25 26 27 28 |
# File 'lib/ey_backup/logger.rb', line 25 def initialize(stdout = $stdout, stderr = $stderr) @stdout, @stderr = stdout, stderr @verbose = false end |
Instance Attribute Details
#stderr ⇒ Object
Returns the value of attribute stderr.
14 15 16 |
# File 'lib/ey_backup/logger.rb', line 14 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
14 15 16 |
# File 'lib/ey_backup/logger.rb', line 14 def stdout @stdout end |
Class Method Details
.quiet ⇒ Object
21 22 23 |
# File 'lib/ey_backup/logger.rb', line 21 def self.quiet new(StringIO.new) end |
Instance Method Details
#clear_alert?(db) ⇒ Boolean
92 93 94 95 96 97 98 99 |
# File 'lib/ey_backup/logger.rb', line 92 def clear_alert?(db) begin File.delete(File.join(@status_path, "#{db}.alert")) true rescue Errno::ENOENT false end end |
#debug(msg) ⇒ Object
105 106 107 |
# File 'lib/ey_backup/logger.rb', line 105 def debug(msg) stdout.puts("#{Time.now} DEBUG: #{msg}") end |
#error(msg, db = nil) ⇒ Object
81 82 83 84 85 |
# File 'lib/ey_backup/logger.rb', line 81 def error(msg, db = nil) stdout.puts("#{Time.now} ERROR: #{msg}") set_alert(msg, db) unless db.nil? push_dashboard_alert("#{msg} Details at /var/log/eybackup.log.", "FAILURE", db) end |
#exception(type, msg) ⇒ Object
101 102 103 |
# File 'lib/ey_backup/logger.rb', line 101 def exception(type, msg) self.error(msg) end |
#info(msg) ⇒ Object
46 47 48 |
# File 'lib/ey_backup/logger.rb', line 46 def info(msg) stdout.puts "#{Time.now} #{msg}" end |
#okay(db, size) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/ey_backup/logger.rb', line 67 def okay(db, size) filepath = File.join(@status_path, "#{db}.sizes") %x{LOG=$(tail -n 100 #{filepath}); echo "$LOG" > #{filepath}} if File.exists?(filepath) %x{echo "#{Time.now()} #{size}" >> #{filepath}} msg = "Backup successful for '#{db}' after previous failure." push_dashboard_alert(msg, 'OKAY', db) if clear_alert?(db) end |
#push_dashboard_alert(message, alert_level, db = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ey_backup/logger.rb', line 30 def push_dashboard_alert(, alert_level, db = nil) .gsub!("\n", '\n') = Shellwords.escape().truncate(255) type="process-dbbackup" type = type + " #{db}" unless db.nil? full_txt= "Severity: #{alert_level}\n" \ + "Time: #{Time.now.to_i}\n" \ + "Type: #{type}\n" \ + "Plugin: exec\n" full_txt = Shellwords.escape(full_txt) full_txt += "raw_message:\\ \\'#{}\\'" alert_command = %Q(echo #{full_txt} | /engineyard/bin/ey-alert.rb 2>&1) verbose "Sending dashboard alert" system(alert_command) end |
#say(msg, newline = true) ⇒ Object
63 64 65 |
# File 'lib/ey_backup/logger.rb', line 63 def say(msg, newline = true) newline ? info(msg) : stdout.print(msg) end |
#set_alert(msg, db) ⇒ Object
87 88 89 90 |
# File 'lib/ey_backup/logger.rb', line 87 def set_alert(msg, db) fullPath = File.join(@status_path, "#{db}.alert") File.open(fullPath, 'a') { |file| file.puts "#{Time.now}: #{msg}"} end |
#set_log_path=(path) ⇒ Object
58 59 60 61 |
# File 'lib/ey_backup/logger.rb', line 58 def set_log_path=(path) @status_path = path FileUtils.mkdir_p(@status_path) end |
#set_verbose ⇒ Object
54 55 56 |
# File 'lib/ey_backup/logger.rb', line 54 def set_verbose() @verbose = true end |
#verbose(msg) ⇒ Object
50 51 52 |
# File 'lib/ey_backup/logger.rb', line 50 def verbose(msg) info(msg) if @verbose end |
#warn(msg, db = nil) ⇒ Object
75 76 77 78 79 |
# File 'lib/ey_backup/logger.rb', line 75 def warn(msg, db = nil) stdout.puts("#{Time.now} WARNING: #{msg}") set_alert(msg, db) unless db.nil? push_dashboard_alert(msg, "WARNING", db) end |