alexreisner/geocoder · error · StandardError

Geocoder tried to log a message with an invalid log level.

Error message

Geocoder tried to log a message with an invalid log level.

What it means

Geocoder's internal logger raises a StandardError when Geocoder (or user code calling Geocoder::Logger.log) passes a log level that is not one of the mapped severities (:debug, :info, :warn, :error, :fatal). The library guards its logging path so a typo or unexpected symbol never silently drops messages.

Solutions

  1. Use only :debug, :info, :warn, :error, :fatal as log levels
  2. Check the configured Geocoder log level option (Geocoder.configure(log: ...)) for typos
  3. Call Geocoder::Logger.valid_level?(level) before logging custom messages
  4. Wrap custom logging calls in a level check

Example fix

// before
Geocoder::Logger.log(:verbose, 'tracing lookup')
// after
Geocoder::Logger.log(:debug, 'tracing lookup')
Defensive patterns

Strategy: validation

Validate before calling

raise unless %i[debug info warn error fatal].include?(level)

Type guard

def valid_log_level?(level); %i[debug info warn error fatal].include?(level); end

Try / catch

begin
  Geocoder::Logger.log(level, msg)
rescue StandardError => e
  warn "log skipped: #{e.message}"
end

Prevention

When it happens

Trigger: Calling Geocoder::Logger.log with a level symbol not in the SEVERITY map (e.g. :verbose, :notice, 'debug' as a string if not normalized), or a lookup/client passing an invalid level internally.

Common situations: Typo in the configured log level or custom middleware calling the logger with a nonstandard level; upgrading Geocoder where a previously accepted level name was removed.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of alexreisner/geocoder@c10bd70121 (2026-09-15). Data as JSON: /api/errors/52c5f9361fb3f503. Report an issue: GitHub.

Appendix: source

Thrown at lib/geocoder/logger.rb:22

  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

View on GitHub (pinned to c10bd70121)