Sha256: 35334f757d50b7de2cb80061b9e4e5c94ea7426e7f013fe1f32dfb4afd6f7aa1

Contents?: true

Size: 1001 Bytes

Versions: 52

Compression:

Stored size: 1001 Bytes

Contents

module God
  
  class SimpleLogger
    DEBUG = 2
    INFO = 4
    WARN = 8
    ERROR = 16
    FATAL = 32
    
    SEV_LABEL = {DEBUG => 'DEBUG',
                 INFO => 'INFO',
                 WARN => 'WARN',
                 ERROR => 'ERROR',
                 FATAL => 'FATAL'}
    
    attr_accessor :datetime_format, :level
    
    def initialize(io)
      @io = io
      @level = INFO
      @datetime_format = "%Y-%m-%d %H:%M:%S"
    end
    
    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
    
    def fatal(msg)
      self.output(FATAL, msg)
    end
    
    def error(msg)
      self.output(ERROR, msg)
    end
    
    def warn(msg)
      self.output(WARN, msg)
    end
    
    def info(msg)
      self.output(INFO, msg)
    end
    
    def debug(msg)
      self.output(DEBUG, msg)
    end
  end
  
end

Version data entries

52 entries across 52 versions & 19 rubygems

Version Path
dguettler-god-0.7.13.2 lib/god/simple_logger.rb
dguettler-god-0.7.13.3 lib/god/simple_logger.rb
dosire-god-0.7.10 lib/god/simple_logger.rb
dosire-god-0.7.12 lib/god/simple_logger.rb
dosire-god-0.7.9 lib/god/simple_logger.rb
dunedain289-god-0.7.12.1 lib/god/simple_logger.rb
dustin-god-0.7.7.1 lib/god/simple_logger.rb
eric-god-0.7.10 lib/god/simple_logger.rb
eric-god-0.7.11 lib/god/simple_logger.rb
eric-god-0.7.12 lib/god/simple_logger.rb
eric-god-0.7.14 lib/god/simple_logger.rb
eric-god-0.7.7 lib/god/simple_logger.rb
fotonauts-god-0.7.10 lib/god/simple_logger.rb
fotonauts-god-0.7.12 lib/god/simple_logger.rb
gohanlonllc-god-0.7.9 lib/god/simple_logger.rb
gordoncww-god-0.7.11.1 lib/god/simple_logger.rb
jreynolds-god-0.7.13 lib/god/simple_logger.rb
jwilkins-god-0.7.9 lib/god/simple_logger.rb
mathieuravaux-god-0.7.11 lib/god/simple_logger.rb
mojombo-god-0.7.10 lib/god/simple_logger.rb