Class: ProMotion::Logger

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

Constant Summary collapse

NAME =
"ProMotion::Logger: "
COLORS =
{
  default:    [ '', '' ],
  red:        [ "\e[0;31m", "\e[0m" ],
  green:      [ "\e[0;32m", "\e[0m" ],
  yellow:     [ "\e[0;33m", "\e[0m" ],
  blue:       [ "\e[0;34m", "\e[0m" ],
  purple:     [ "\e[0;35m", "\e[0m" ],
  cyan:       [ "\e[0;36m", "\e[0m" ]
}
LEVELS =
{
  off:        [],
  error:      [:error],
  warn:       [:error, :warn],
  info:       [:error, :warn, :info],
  verbose:    [:error, :warn, :info, :debug, :verbose],
  debug:      [:error, :warn, :info, :debug, :verbose]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#levelObject

Returns the value of attribute level.



3
4
5
# File 'lib/ProMotion/helpers/logger.rb', line 3

def level
  @level
end

Instance Method Details

#debug(message) ⇒ Object



53
54
55
# File 'lib/ProMotion/helpers/logger.rb', line 53

def debug(message) 
  self.log('DEBUG', message, :purple) if self.levels.include?(:debug)
end

#deprecated(message) ⇒ Object



45
46
47
# File 'lib/ProMotion/helpers/logger.rb', line 45

def deprecated(message)
  self.log('DEPRECATED', message, :yellow) if self.levels.include?(:warn)
end

#error(message) ⇒ Object



41
42
43
# File 'lib/ProMotion/helpers/logger.rb', line 41

def error(message)
  self.log('ERROR', message, :red) if self.levels.include?(:error)
end

#info(message) ⇒ Object



57
58
59
# File 'lib/ProMotion/helpers/logger.rb', line 57

def info(message) 
  self.log('INFO', message, :green) if self.levels.include?(:info)
end

#levelsObject



30
31
32
# File 'lib/ProMotion/helpers/logger.rb', line 30

def levels
  LEVELS[self.level] || []
end

#log(label, message_text, color) ⇒ Object

Usage: PM.logger.log(“ERROR”, “message here”, :red)



35
36
37
38
39
# File 'lib/ProMotion/helpers/logger.rb', line 35

def log(label, message_text, color) 
  return if RUBYMOTION_ENV == "test"
  color = COLORS[color] || COLORS[:default]
  puts color[0] + NAME + "[#{label}] #{message_text}" + color[1]
end

#warn(message) ⇒ Object



49
50
51
# File 'lib/ProMotion/helpers/logger.rb', line 49

def warn(message) 
  self.log('WARN', message, :yellow) if self.levels.include?(:warn)
end