Class: Loki::Logger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/loki/logger.rb

Constant Summary collapse

COLORS =
{
  :red     => 31,
  :green   => 32,
  :yellow  => 33,
  :blue    => 34,
  :magenta => 35,
  :cyan    => 36,
  :white   => 37,
  :r       => 31,
  :g       => 32,
  :y       => 33,
  :b       => 34,
  :m       => 35,
  :c       => 36,
  :w       => 37
}

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



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

def initialize
  @indent = 0
end

Instance Method Details

#indented?Boolean

Returns:

  • (Boolean)


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

def indented?
  @indent > 0
end

#lineObject



49
50
51
# File 'lib/loki/logger.rb', line 49

def line
  $stdout.puts("-" * 80) if @indent == 0
end

#paint(text, color = :white) ⇒ Object



56
57
58
# File 'lib/loki/logger.rb', line 56

def paint(text, color = :white)
  "\e[#{COLORS[color]}m#{text}\e[0m"
end

#parse(text) ⇒ Object



61
62
63
64
65
66
# File 'lib/loki/logger.rb', line 61

def parse(text)
  colors = COLORS.keys.collect(&:to_s).join('|')
  text.gsub(/\<(#{colors})\>(.*)\<\/\1\>/) do
    paint($2, $1.to_sym)
  end
end

#pullObject



39
40
41
# File 'lib/loki/logger.rb', line 39

def pull
  @indent -= 1
end

#pushObject



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

def push
  @indent += 1
end

#puts(text, mark = ">") ⇒ Object



44
45
46
# File 'lib/loki/logger.rb', line 44

def puts(text, mark = ">")
  $stdout.puts((" " * @indent * 2) + "#{mark} #{parse(text)}")
end