class Gridium::Log

Public Class Methods

add_device(device) click to toggle source
# File lib/log.rb, line 85
def add_device device
  @@devices ||= []
  log.attach(device)
  @@devices << device
  log.add(log.level, "device added: #{File.absolute_path(device)}")
end
close() click to toggle source
# File lib/log.rb, line 92
def close
  @@devices.each { |dev| @@logger.detach(dev) }
  @@devices.clear
  log.close if log
end
debug(msg) click to toggle source

more generic than INFO, useful for debugging issues DEBUG = 0 generic, useful information about system operation INFO = 1 a warning WARN = 2 a handleable error condition ERROR = 3 an unhandleable error that results in a program crash FATAL = 4 an unknown message that should always be logged UNKNOWN = 5

# File lib/log.rb, line 65
def debug(msg)
  log.debug(msg)
end
error(msg) click to toggle source
# File lib/log.rb, line 79
def error(msg)
  log.error(msg)
  Driver.save_screenshot('error') if Gridium.config.screenshot_on_failure
  SpecData.verification_errors << msg
end
info(msg) click to toggle source
# File lib/log.rb, line 69
def info(msg)
  log.info(msg)
end
warn(msg) click to toggle source
# File lib/log.rb, line 73
def warn(msg)
  log.warn(msg)
  Driver.save_screenshot('warning') if Gridium.config.screenshot_on_failure
  SpecData.execution_warnings << msg
end

Private Class Methods

initialize_logger() click to toggle source
# File lib/log.rb, line 105
def initialize_logger
  # log to STDOUT and file
  logger ||= Logger.new(STDOUT)

  # messages that have the set level or higher will be logged
  case Gridium.config.log_level
    when :debug then
      level = Logger::DEBUG
    when :info then
      level = Logger::INFO
    when :warn then
      level = Logger::WARN
    when :error then
      level = Logger::ERROR
    when :fatal then
      level = Logger::FATAL
  end

  logger.level = level

  logger.formatter = proc do |severity, datetime, progname, msg|
    base_msg = "[#{datetime.strftime('%Y-%m-%d %H:%M:%S')}][#{severity}]"
    sev = severity.to_s
    if sev.eql?("DEBUG")
      "#{base_msg}   #{msg}\n"
    elsif sev.eql?("INFO")
      "#{base_msg}  > #{msg}\n"
    elsif sev.eql?("WARN")
      "#{base_msg}  X #{msg}\n"
    else
      "#{base_msg} X #{msg}\n"
    end
  end
  logger
end
log() click to toggle source
# File lib/log.rb, line 101
def log
  @@logger ||= initialize_logger
end