Class: MotionPrime::Logger

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



10
11
12
# File 'motion-prime/services/logger.rb', line 10

def initialize
  @default_level = Config.logger.level.nil? ? :info : Config.logger.level
end

Instance Method Details

#current_levelObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'motion-prime/services/logger.rb', line 38

def current_level
  current_level = self.class.level || @default_level
  case current_level.to_s
  when 'error'
    LOGGER_ERROR_LEVEL
  when 'info'
    LOGGER_INFO_LEVEL
  when 'debug'
    LOGGER_DEBUG_LEVEL
  when 'dealloc'
    LOGGER_DEALLOC_LEVEL
  else
    2
  end
end

#dealloc_itemsObject



34
35
36
# File 'motion-prime/services/logger.rb', line 34

def dealloc_items
  self.class.dealloc_items || []
end

#dealloc_message(type, object, *args) ⇒ Object



26
27
28
29
30
31
32
# File 'motion-prime/services/logger.rb', line 26

def dealloc_message(type, object, *args)
  if LOGGER_DEALLOC_LEVEL <= current_level
    if dealloc_items.include?(type.to_s)
      pp "Deallocating #{type}", object.object_id, object.to_s, *args
    end
  end
end

#debug(*args) ⇒ Object



22
23
24
# File 'motion-prime/services/logger.rb', line 22

def debug(*args)
  pp(*args) if LOGGER_DEBUG_LEVEL <= current_level
end

#error(*args) ⇒ Object



14
15
16
# File 'motion-prime/services/logger.rb', line 14

def error(*args)
  pp(*args) if LOGGER_ERROR_LEVEL <= current_level
end

#info(*args) ⇒ Object



18
19
20
# File 'motion-prime/services/logger.rb', line 18

def info(*args)
  pp(*args) if LOGGER_INFO_LEVEL <= current_level
end