Sha256: b74328d4555b4724af01acda314b2e3980748033ae8c319487fc7981e82bb6f9

Contents?: true

Size: 894 Bytes

Versions: 18

Compression:

Stored size: 894 Bytes

Contents

module Hyalite
  module Logger
    ERROR_LEVELS = %i(error warn info debug)

    def self.log_level=(level)
      @log_level_index = ERROR_LEVELS.index(level)
    end

    def self.log_level
      @log_level_index ||= ERROR_LEVELS.index(:warn)
      ERROR_LEVELS[@log_level_index]
    end

    def self.error(obj)
      if self.log_level == :error
        output(:error, obj)
      end
    end

    def self.warn(obj)
      if @log_level_index <=  ERROR_LEVELS.index(:warn)
        output(:warn, obj)
      end
    end

    def self.info(obj)
      if @log_level_index <=  ERROR_LEVELS.index(:info)
        output(:info, obj)
      end
    end

    def self.debug(obj)
      output(:debug, obj)
    end

    def self.output(level, obj)
      case obj
      when String
        puts "#{level.upcase}: #{obj}"
      else
        puts "#{level.upcase}: #{obj.inspect}"
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
hyalite-0.3.4 lib/hyalite/logger.rb
hyalite-0.3.2 lib/hyalite/logger.rb
hyalite-0.3.1 lib/hyalite/logger.rb
hyalite-0.3.0 lib/hyalite/logger.rb
hyalite-0.2.8 lib/hyalite/logger.rb
hyalite-0.2.7 lib/hyalite/logger.rb
hyalite-0.2.6 lib/hyalite/logger.rb
hyalite-0.2.5 lib/hyalite/logger.rb
hyalite-0.2.4 lib/hyalite/logger.rb
hyalite-0.2.3 lib/hyalite/logger.rb
hyalite-0.2.2 lib/hyalite/logger.rb
hyalite-0.2.1 lib/hyalite/logger.rb
hyalite-0.2.0 lib/hyalite/logger.rb
hyalite-0.1.1 client/hyalite/logger.rb
hyalite-0.1.0 client/hyalite/logger.rb
hyalite-0.0.6 client/hyalite/logger.rb
hyalite-0.0.5 client/hyalite/logger.rb
hyalite-0.0.4 client/hyalite/logger.rb