Class: Navy::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/logger.rb

Constant Summary collapse

COLOURS =
{
  :black          => 30,
  :red            => 31,
  :green          => 32,
  :yellow         => 33,
  :blue           => 34,
  :magenta        => 35,
  :cyan           => 36,
  :bright_black   => 30,
  :bright_red     => 31,
  :bright_green   => 32,
  :bright_yellow  => 33,
  :bright_blue    => 34,
  :bright_magenta => 35,
  :bright_cyan    => 36
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#prefixObject (readonly)

Returns the value of attribute prefix.



19
20
21
# File 'lib/navy/logger.rb', line 19

def prefix
  @prefix
end

Instance Method Details

#color(color, message) ⇒ Object



21
22
23
# File 'lib/navy/logger.rb', line 21

def color(color, message)
  "\033[0;#{COLOURS[color]}m#{message}\033[0;00m"
end

#debug(message) ⇒ Object



37
38
39
# File 'lib/navy/logger.rb', line 37

def debug(message)
  log message
end

#error(message) ⇒ Object



33
34
35
# File 'lib/navy/logger.rb', line 33

def error(message)
  log color(:red, message)
end

#info(message) ⇒ Object



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

def info(message)
  log color(:yellow, message)
end

#notice(message) ⇒ Object



25
26
27
# File 'lib/navy/logger.rb', line 25

def notice(message)
  log color(:cyan,message)
end

#threaded!Object



41
42
43
44
45
46
# File 'lib/navy/logger.rb', line 41

def threaded!
  thread = Thread.current.object_id
  colorid = (thread/7) % COLOURS.count
  colorkey = COLOURS.keys[colorid]
  @prefix = color(colorkey, "(#{thread}):")
end