Class: MotionPrime::Logger
- Inherits:
-
Object
- Object
- MotionPrime::Logger
- Defined in:
- motion-prime/services/logger.rb
Constant Summary collapse
- LOGGER_ERROR_LEVEL =
0
- LOGGER_INFO_LEVEL =
1
- LOGGER_DEBUG_LEVEL =
2
- LOGGER_DEALLOC_LEVEL =
3
- COLORS =
{ red: [ "\e[0;31m", "\e[0m" ], green: [ "\e[0;32m", "\e[0m" ], yellow: [ "\e[0;33m", "\e[0m" ], blue: [ "\e[0;34m", "\e[0m" ], none: [ "", ""] }
Instance Attribute Summary collapse
-
#disabled ⇒ Object
Returns the value of attribute disabled.
Instance Method Summary collapse
- #dealloc_message(type, object, *args) ⇒ Object
- #debug(*args) ⇒ Object
- #error(*args) ⇒ Object
- #info(*args) ⇒ Object
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
-
#log(objects, label = '', color = :none) ⇒ Object
Log message, colorized if using simulator.
-
#output(message) ⇒ Object
Output message, using “puts” for simulator and NSLog for Device.
Constructor Details
Instance Attribute Details
#disabled ⇒ Object
Returns the value of attribute disabled.
17 18 19 |
# File 'motion-prime/services/logger.rb', line 17 def disabled @disabled end |
Instance Method Details
#dealloc_message(type, object, *args) ⇒ Object
64 65 66 67 68 69 70 |
# File 'motion-prime/services/logger.rb', line 64 def (type, object, *args) if LOGGER_DEALLOC_LEVEL <= current_level if dealloc_items.include?(type.to_s) log([object.object_id, object.to_s] + args, "DEALLOC #{type}", :yellow) end end end |
#debug(*args) ⇒ Object
60 61 62 |
# File 'motion-prime/services/logger.rb', line 60 def debug(*args) log(args, "PRIME_DEBUG", :yellow) if LOGGER_DEBUG_LEVEL <= current_level end |
#error(*args) ⇒ Object
52 53 54 |
# File 'motion-prime/services/logger.rb', line 52 def error(*args) log(args, "PRIME_ERROR", :red) if LOGGER_ERROR_LEVEL <= current_level end |
#info(*args) ⇒ Object
56 57 58 |
# File 'motion-prime/services/logger.rb', line 56 def info(*args) log(args, "PRIME_INFO", :green) if LOGGER_INFO_LEVEL <= current_level end |
#log(objects, label = '', color = :none) ⇒ Object
Log message, colorized if using simulator.
28 29 30 31 32 33 34 35 36 37 |
# File 'motion-prime/services/logger.rb', line 28 def log(objects, label = '', color = :none) = "#{label || 'PRIME_LOG'} : " + Array.wrap(objects).map(&:inspect).join(',') if Device.simulator? color_parts = COLORS[color] || COLORS[:none] output(color_parts.first + + color_parts.last) else output() end objects end |
#output(message) ⇒ Object
Output message, using “puts” for simulator and NSLog for Device.
42 43 44 45 46 47 48 49 50 |
# File 'motion-prime/services/logger.rb', line 42 def output() return if disabled if Device.simulator? puts() else NSLog() end end |