Completed
Push — master ( f48217...560331 )
by Yoh
01:11
created

Logger.error()   A

Complexity

Conditions 2

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
1
module Hyalite
2
  module Logger
3
    ERROR_LEVELS = %i(error warn info debug)
4
5
    def self.log_level=(level)
6
      @log_level_index = ERROR_LEVELS.index(level)
7
    end
8
9
    def self.log_level
10
      @log_level_index ||= ERROR_LEVELS.index(:warn)
11
      ERROR_LEVELS[@log_level_index]
12
    end
13
14
    def self.error(obj)
15
      if self.log_level == :error
16
        output(:error, obj)
17
      end
18
    end
19
20
    def self.warn(obj)
21
      if @log_level_index <=  ERROR_LEVELS.index(:warn)
22
        output(:warn, obj)
23
      end
24
    end
25
26
    def self.info(obj)
27
      if @log_level_index <=  ERROR_LEVELS.index(:info)
28
        output(:info, obj)
29
      end
30
    end
31
32
    def self.debug(obj)
33
      output(:debug, obj)
34
    end
35
36
    def self.output(level, obj)
37
      case obj
38
      when String
39
        puts "#{level.upcase}: #{obj}"
40
      else
41
        puts "#{level.upcase}: #{obj.inspect}"
42
      end
43
    end
44
  end
45
end
46