Class: ProMotion::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/ProMotion/logger/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],
  debug:      [:error, :warn, :info, :debug],
  verbose:    [: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/logger/logger.rb', line 3

def level
  @level
end

Instance Method Details

#debug(message) ⇒ Object



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

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

#deprecated(message) ⇒ Object



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

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

#error(message) ⇒ Object



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

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

#info(message) ⇒ Object



62
63
64
# File 'lib/ProMotion/logger/logger.rb', line 62

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

#levelsObject



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

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

#log(label, message_text, color) ⇒ Object

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



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

def log(label, message_text, color)
  show_deprecation_warning

  mp "#{NAME}[#{label}] #{message_text}", force_color: color
end

#show_deprecation_warningObject



66
67
68
# File 'lib/ProMotion/logger/logger.rb', line 66

def show_deprecation_warning
  mp "PM.logger.log has been deprecated. Please update to motion_print: https://github.com/OTGApps/motion_print", force_color: :yellow
end

#warn(message) ⇒ Object



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

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