Sha256: a3693243daa27b18d7b9a44797f293d63ae96f0f209796ff6171c0b6efcef6b9

Contents?: true

Size: 1011 Bytes

Versions: 9

Compression:

Stored size: 1011 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

9 entries across 9 versions & 2 rubygems

Version Path
olgen-god-0.9.2 lib/god/simple_logger.rb
olgen-god-0.9.1 lib/god/simple_logger.rb
olgen-god-0.9.0 lib/god/simple_logger.rb
god-0.8.0 lib/god/simple_logger.rb
olgen-god-0.8.2 lib/god/simple_logger.rb
olgen-god-0.8.1 lib/god/simple_logger.rb
olgen-god-0.8.0 lib/god/simple_logger.rb
god-0.7.22 lib/god/simple_logger.rb
god-0.7.21 lib/god/simple_logger.rb