Sha256: 11dd208812f971a4cb46eb845a1a29cf67b558cd0ec61a6539ded07af0186303

Contents?: true

Size: 1.1 KB

Versions: 50

Compression:

Stored size: 1.1 KB

Contents

require 'logger'

module Geocoder

  def self.log(level, message)
    Logger.instance.log(level, message)
  end

  class Logger
    include Singleton

    SEVERITY = {
      debug: ::Logger::DEBUG,
      info: ::Logger::INFO,
      warn: ::Logger::WARN,
      error: ::Logger::ERROR,
      fatal: ::Logger::FATAL
    }

    def log(level, message)
      unless valid_level?(level)
        raise StandardError, "Geocoder tried to log a message with an invalid log level."
      end
      if current_logger.respond_to? :add
        current_logger.add(SEVERITY[level], message)
      else
        raise Geocoder::ConfigurationError, "Please specify valid logger for Geocoder. " +
        "Logger specified must be :kernel or must respond to `add(level, message)`."
      end
      nil
    end

    private # ----------------------------------------------------------------

    def current_logger
      logger = Geocoder.config[:logger]
      if logger == :kernel
        logger = Geocoder::KernelLogger.instance
      end
      logger
    end

    def valid_level?(level)
      SEVERITY.keys.include?(level)
    end
  end
end

Version data entries

50 entries across 50 versions & 4 rubygems

Version Path
geocoder-1.8.3 lib/geocoder/logger.rb
geocoder-1.8.2 lib/geocoder/logger.rb
geocoder-1.8.1 lib/geocoder/logger.rb
geocoder-1.8.0 lib/geocoder/logger.rb
geocoder-1.7.5 lib/geocoder/logger.rb
geocoder-1.7.4 lib/geocoder/logger.rb
geocoder-1.7.3 lib/geocoder/logger.rb
geocoder-1.7.2 lib/geocoder/logger.rb
geocoder-1.7.1 lib/geocoder/logger.rb
geocoder-1.7.0 lib/geocoder/logger.rb
geocoder-1.6.7 lib/geocoder/logger.rb
geocoder-1.6.6 lib/geocoder/logger.rb
geocoder-1.6.5 lib/geocoder/logger.rb
geocoder-1.6.4 lib/geocoder/logger.rb
geocoder-1.6.3 lib/geocoder/logger.rb
geocoder-1.6.2 lib/geocoder/logger.rb
geocoder-1.6.1 lib/geocoder/logger.rb
geocoder-1.6.0 lib/geocoder/logger.rb
geocoder-1.5.2 lib/geocoder/logger.rb
really-broken-geocoder-2.0.0 lib/geocoder/logger.rb