Module: Dronejob::Modules::Log

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/dronejob/modules/log.rb

Constant Summary collapse

COLOR_BOLD =
"\e[1m"
COLOR_RED =
"\e[31m"
COLOR_RED_BG =
"\e[41m"
COLOR_WHITE =
"\e[38;5;15m"
COLOR_GREY =
"\e[38;5;245m"
COLOR_GREY_BG =
"\e[48;5;255m"
COLOR_END =
"\e[0m"

Instance Method Summary collapse

Instance Method Details

#alert(message) ⇒ Object



115
116
117
# File 'lib/dronejob/modules/log.rb', line 115

def alert(message)
  log(:alert, message)
end

#backtrace(lines) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/dronejob/modules/log.rb', line 93

def backtrace(lines)
  lines.each do |line|
    line.gsub!("#{Dir.pwd}/", '')
    (file, lineno, info) = line.split(":")
    if %r{ruby/?gems}.match(line).nil?
      if log_stdout?
        log(:error, "#{COLOR_GREY_BG}#{COLOR_GREY} #{lineno.rjust(5, ' ')} #{COLOR_END} #{COLOR_RED}#{file}#{COLOR_END} #{COLOR_GREY}#{info}#{COLOR_END}")
      else
        log(:error, " - #{file}:#{lineno} #{info}")
      end
    end
  end
end

#critical(message) ⇒ Object



111
112
113
# File 'lib/dronejob/modules/log.rb', line 111

def critical(message)
  log(:critical, message)
end

#debug(message) ⇒ Object



60
61
62
# File 'lib/dronejob/modules/log.rb', line 60

def debug(message)
  log(:debug, message)
end

#emergency(message) ⇒ Object



119
120
121
# File 'lib/dronejob/modules/log.rb', line 119

def emergency(message)
  log(:emergency, message)
end

#error(message) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/dronejob/modules/log.rb', line 76

def error(message)
  if message.kind_of?(StandardError)
    if option(:dronejob_log) == "google"
      log(:error, "#{message.backtrace.first}: #{message.message} (#{message.class})\n\t#{message.backtrace.drop(1).join("\n\t")}")
    else
      if log_stdout?
        log(:error, "#{COLOR_RED_BG}#{COLOR_BOLD}#{COLOR_WHITE} ERROR #{COLOR_END} #{COLOR_BOLD}#{message.class}: #{COLOR_RED}#{message.message}#{COLOR_END}")
      else
        log(:error, "[ERROR] #{message.class}: #{message.message}")
      end
      backtrace(message.backtrace)
    end
  else
    log(:error, message)
  end
end

#error!(message) ⇒ Object



107
108
109
# File 'lib/dronejob/modules/log.rb', line 107

def error!(message)
  throw message
end

#info(message) ⇒ Object



64
65
66
# File 'lib/dronejob/modules/log.rb', line 64

def info(message)
  log(:info, message)
end

#log(level, message) ⇒ Object



56
57
58
# File 'lib/dronejob/modules/log.rb', line 56

def log(level, message)
  self.class.log(level, message, self)
end

#notice(message) ⇒ Object



68
69
70
# File 'lib/dronejob/modules/log.rb', line 68

def notice(message)
  log(:notice, message)
end

#warning(message) ⇒ Object



72
73
74
# File 'lib/dronejob/modules/log.rb', line 72

def warning(message)
  log(:warning, message)
end