Sha256: 6b844d38a494b24eaf4ed2f82bc0272f397a5030af3bd97959410a6641b24711

Contents?: true

Size: 810 Bytes

Versions: 3

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true

module GoogleDistanceMatrix
  # Logger class for Google Distance Matrix
  class Logger
    PREFIXES = %w[google_distance_matrix].freeze
    LEVELS = %w[fatal error warn info debug].freeze

    attr_reader :backend

    def initialize(backend = nil)
      @backend = backend
    end

    LEVELS.each do |level|
      define_method level do |*args|
        options = args.extract_options!.with_indifferent_access

        msg = args.first
        tags = PREFIXES.dup.concat Array.wrap(options[:tag])

        backend&.public_send level, tag_msg(msg, tags)
      end
    end

    def level
      backend&.level || 1
    end

    private

    def tag_msg(msg, tags)
      msg_buffer = tags.map { |tag| "[#{tag}]" }
      msg_buffer << msg
      msg_buffer.join ' '
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
google_distance_matrix-0.7.1 lib/google_distance_matrix/logger.rb
google_distance_matrix-0.7.0 lib/google_distance_matrix/logger.rb
google_distance_matrix-0.6.7 lib/google_distance_matrix/logger.rb