Class: God::SimpleLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/god/simple_logger.rb

Direct Known Subclasses

Logger

Constant Summary collapse

DEBUG =
2
INFO =
4
WARN =
8
ERROR =
16
FATAL =
32
SEV_LABEL =
{DEBUG => 'DEBUG',
INFO => 'INFO',
WARN => 'WARN',
ERROR => 'ERROR',
FATAL => 'FATAL'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ SimpleLogger

Returns a new instance of SimpleLogger.



18
19
20
21
22
# File 'lib/god/simple_logger.rb', line 18

def initialize(io)
  @io = io
  @level = INFO
  @datetime_format = "%Y-%m-%d %H:%M:%S"
end

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



16
17
18
# File 'lib/god/simple_logger.rb', line 16

def datetime_format
  @datetime_format
end

#levelObject

Returns the value of attribute level.



16
17
18
# File 'lib/god/simple_logger.rb', line 16

def level
  @level
end

Instance Method Details

#debug(msg) ⇒ Object



48
49
50
# File 'lib/god/simple_logger.rb', line 48

def debug(msg)
  self.output(DEBUG, msg)
end

#error(msg) ⇒ Object



36
37
38
# File 'lib/god/simple_logger.rb', line 36

def error(msg)
  self.output(ERROR, msg)
end

#fatal(msg) ⇒ Object



32
33
34
# File 'lib/god/simple_logger.rb', line 32

def fatal(msg)
  self.output(FATAL, msg)
end

#info(msg) ⇒ Object



44
45
46
# File 'lib/god/simple_logger.rb', line 44

def info(msg)
  self.output(INFO, msg)
end

#output(level, msg) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/god/simple_logger.rb', line 24

def output(level, msg)
  return if level < self.level
  
  time = Time.now.strftime(self.datetime_format)
  label = SEV_LABEL[level]
  @io.print(label[0..0], ' [', time, '] ', label.rjust(5), ': ',  msg, "\n")
end

#warn(msg) ⇒ Object



40
41
42
# File 'lib/god/simple_logger.rb', line 40

def warn(msg)
  self.output(WARN, msg)
end