Class: Knapsack::Logger

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

Constant Summary collapse

DEBUG =
0
INFO =
1
WARN =
2
UnknownLogLevel =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#levelObject

Returns the value of attribute level.



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

def level
  @level
end

Instance Method Details

#debug(text = nil) ⇒ Object



23
24
25
26
# File 'lib/knapsack/logger.rb', line 23

def debug(text=nil)
  return if level != DEBUG
  puts text
end

#info(text = nil) ⇒ Object



28
29
30
31
# File 'lib/knapsack/logger.rb', line 28

def info(text=nil)
  return if level > INFO
  puts text
end

#log(level, text = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/knapsack/logger.rb', line 11

def log(level, text=nil)
  level_method =
    case level
    when DEBUG then :debug
    when INFO then :info
    when WARN then :warn
    else raise UnknownLogLevel
    end

  public_send(level_method, text)
end

#warn(text = nil) ⇒ Object



33
34
35
36
# File 'lib/knapsack/logger.rb', line 33

def warn(text=nil)
  return if level > WARN
  puts text
end