{"record":{"id":"52c5f9361fb3f503","repo":"alexreisner/geocoder","slug":"geocoder-tried-to-log-a-message-with-an-invalid-log-level","errorCode":null,"errorMessage":"Geocoder tried to log a message with an invalid log level.","messagePattern":"Geocoder tried to log a message with an invalid log level\\.","errorType":"exception","errorClass":"StandardError","httpStatus":null,"severity":"error","filePath":"lib/geocoder/logger.rb","lineNumber":22,"sourceCode":"\n  def self.log(level, message)\n    Logger.instance.log(level, message)\n  end\n\n  class Logger\n    include Singleton\n\n    SEVERITY = {\n      debug: ::Logger::DEBUG,\n      info: ::Logger::INFO,\n      warn: ::Logger::WARN,\n      error: ::Logger::ERROR,\n      fatal: ::Logger::FATAL\n    }\n\n    def log(level, message)\n      unless valid_level?(level)\n        raise StandardError, \"Geocoder tried to log a message with an invalid log level.\"\n      end\n      if current_logger.respond_to? :add\n        current_logger.add(SEVERITY[level], message)\n      else\n        raise Geocoder::ConfigurationError, \"Please specify valid logger for Geocoder. \" +\n        \"Logger specified must be :kernel or must respond to `add(level, message)`.\"\n      end\n      nil\n    end\n\n    private # ----------------------------------------------------------------\n\n    def current_logger\n      logger = Geocoder.config[:logger]\n      if logger == :kernel\n        logger = Geocoder::KernelLogger.instance\n      end\n      logger","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/alexreisner/geocoder/blob/c10bd701215110ebe65da1c8b8b410b124208fd2/lib/geocoder/logger.rb#L4-L40","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use only :debug, :info, :warn, :error, :fatal as log levels","Check the configured Geocoder log level option (Geocoder.configure(log: ...)) for typos","Call Geocoder::Logger.valid_level?(level) before logging custom messages","Wrap custom logging calls in a level check"],"exampleFix":"// before\nGeocoder::Logger.log(:verbose, 'tracing lookup')\n// after\nGeocoder::Logger.log(:debug, 'tracing lookup')","handlingStrategy":"validation","validationCode":"raise unless %i[debug info warn error fatal].include?(level)","typeGuard":"def valid_log_level?(level); %i[debug info warn error fatal].include?(level); end","tryCatchPattern":"begin\n  Geocoder::Logger.log(level, msg)\nrescue StandardError => e\n  warn \"log skipped: #{e.message}\"\nend","preventionTips":["Only use the five documented severity symbols","Centralize logging through a wrapper that validates the level","Check Geocoder.configure(log:) value after config load"],"tags":["ruby","logging","configuration"],"backgroundTag":"invalid-enum-value","analyzedSha":"c10bd701215110ebe65da1c8b8b410b124208fd2","analyzedAt":"2026-09-15T23:43:32.125Z","contentChangedAt":"2026-09-15T23:43:32.125Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}