aboutsummaryrefslogtreecommitdiff
path: root/core/logger.rb
blob: 086967c0d1c6894e342aaeb9f2f2330d508459fa (plain) (blame)
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
39
40
41
42
43
44
45
46
module Dinobot
  module Core
    class Logger
      @@instance = nil
      @@mutex = Mutex.new

      def in(*lines)
        pout("\e[32m<<\e[0m ", *lines)
      end

      def out(*lines)
        pout("\e[36m>>\e[0m ", *lines)
      end

      def info(*lines)
        pout("\e[33m==\e[0m ", *lines)
      end

      def error(*lines)
        pout("\e[31m!!\e[0m ", *lines)
      end

      def indent(*lines)
        pout('   ', *lines)
      end

      private

      def pout(prefix, *lines)
        puts lines.join("\n").gsub(/^/, prefix)
      end

      class << self
        def instance
          return @@instance if @@instance

          @@mutex.synchronize do
            @@instance ||= new
          end
        end
      end

      private_class_method :allocate, :new
    end
  end
end