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'}
CONSTANT_TO_SYMBOL =
{ 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.



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

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.



22
23
24
# File 'lib/god/simple_logger.rb', line 22

def datetime_format
  @datetime_format
end

#levelObject

Returns the value of attribute level.



22
23
24
# File 'lib/god/simple_logger.rb', line 22

def level
  @level
end

Instance Method Details

#debug(msg) ⇒ Object



54
55
56
# File 'lib/god/simple_logger.rb', line 54

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

#error(msg) ⇒ Object



42
43
44
# File 'lib/god/simple_logger.rb', line 42

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

#fatal(msg) ⇒ Object



38
39
40
# File 'lib/god/simple_logger.rb', line 38

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

#info(msg) ⇒ Object



50
51
52
# File 'lib/god/simple_logger.rb', line 50

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

#output(level, msg) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/god/simple_logger.rb', line 30

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



46
47
48
# File 'lib/god/simple_logger.rb', line 46

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