File: logger.rb

package info (click to toggle)
ruby-knapsack 4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,092 kB
  • sloc: ruby: 2,883; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 642 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Knapsack
  class Logger
    attr_accessor :level

    DEBUG = 0
    INFO = 1
    WARN = 2

    UnknownLogLevel = Class.new(StandardError)

    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

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

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

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