Logger.error()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 5
loc 5
rs 9.4285
c 1
b 0
f 0
1
module Rapis
2
  class TermColor
3
    class << self
4
      def green(msg)
5
        colorize 32, msg
6
      end
7
8
      def yellow(msg)
9
        colorize 33, msg
10
      end
11
12
      def red(msg)
13
        colorize 31, msg
14
      end
15
16
      def colorize(num, msg)
17
        "\e[#{num}m#{msg}\e[0m"
18
      end
19
    end
20
  end
21
22
  def self.logger
23
    Rapis::Logger.instance
24
  end
25
26
  #
27
  # Default logger
28
  #
29
  class Logger < Logger
30
    include Singleton
31
32
    def initialize
33
      super(STDERR)
34
35
      self.formatter = proc do |_severity, _datetime, _progname, msg|
36
        "#{msg}\n"
37
      end
38
39
      self.level = Logger::INFO
40
    end
41 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
42
    def debug(msg, progname = nil, method_name = nil)
43
      super(progname) { { method_name: method_name, message: msg } }
44
    end
45
46
    def info(msg)
47
      super { Rapis::TermColor.green(msg) }
48
    end
49
50
    def warn(msg)
51
      super { Rapis::TermColor.yellow(msg) }
52
    end
53
54
    def fatal(msg)
55
      super { Rapis::TermColor.red(msg) }
56
    end
57 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
58
    def error(msg, backtrace, progname = nil, method_name = nil)
59
      super(progname) do
60
        { method_name: method_name, message: msg, backtrace: backtrace }
61
      end
62
    end
63
  end
64
end
65