roidrage/lograge · warning

config.lograge.log_format is deprecated. Use config.lograge.

Error message

config.lograge.log_format is deprecated. Use config.lograge.formatter instead.

What it means

lograge is a Rails gem that collapses verbose multi-line request logs into single-line output. This message is an ActiveSupport::Deprecation warning (horizon 1.0, lib/lograge.rb:229-231) emitted once at Rails boot when an initializer sets the legacy key config.lograge.log_format instead of config.lograge.formatter. A compatibility shim (support_deprecated_config, marked 'TODO: Remove with version 1.0' at lib/lograge.rb:213) still honors the old key by mapping the symbol to a formatter class: :lograge becomes Lograge::Formatters::KeyValue and :json becomes Lograge::Formatters::Json. It is non-fatal today, but in lograge 1.0 the shim is deleted and log_format will be silently ignored, so log output reverts to the default format.

Source

Thrown at lib/lograge.rb:220

    require 'lograge/rails_ext/action_cable/server/base' if defined?(ActionCable)

    Lograge.remove_existing_log_subscriptions
  end

  def rack_cache_hashlike?(app)
    app.config.action_dispatch.rack_cache&.respond_to?(:[]=)
  end
  private_class_method :rack_cache_hashlike?

  # TODO: Remove with version 1.0

  def support_deprecated_config
    return unless lograge_config.log_format

    legacy_log_format = lograge_config.log_format
    warning = 'config.lograge.log_format is deprecated. Use config.lograge.formatter instead.'
    deprecator.warn(warning, caller)
    legacy_log_format = :key_value if legacy_log_format == :lograge
    lograge_config.formatter = "Lograge::Formatters::#{legacy_log_format.to_s.classify}".constantize.new
  end

  def lograge_config
    application.config.lograge
  end

  def deprecator
    @deprecator ||= ActiveSupport::Deprecation.new('1.0', 'Lograge')
  end

  if ::ActiveSupport::VERSION::MAJOR >= 8 ||
     (::ActiveSupport::VERSION::MAJOR >= 7 && ::ActiveSupport::VERSION::MINOR >= 1)
    def notification_listeners_for(name)
      ActiveSupport::Notifications.notifier.all_listeners_for(name)
    end
  else

View on GitHub (pinned to e5caed7775)

Solutions

  1. In the file flagged by the warning's caller backtrace, replace `config.lograge.log_format = :json` with `config.lograge.formatter = Lograge::Formatters::Json.new`.
  2. If you used `log_format = :lograge`, switch to `config.lograge.formatter = Lograge::Formatters::KeyValue.new` — that is the exact legacy mapping (lib/lograge.rb:221).
  3. If you used `:raw`, use `Lograge::Formatters::Raw.new`; any other symbol X maps to `Lograge::Formatters::X.classify`, so prefer the explicit class instance instead.
  4. Search the whole config tree for stray copies: `grep -rn "log_format" config/` — environment-specific files often carry a second one.
  5. For custom output, pass any object responding to call(severity, time, progname, msg) — a lambda or a Lograge::Formatters::Base subclass instance — as config.lograge.formatter.
  6. Reboot and verify: `bin/rails runner 'puts Rails.application.config.lograge.formatter.class'` — the deprecation warning must be gone and log lines unchanged.

Example fix

# before (config/initializers/lograge.rb)
Rails.application.configure do
  config.lograge.enabled = true
  config.lograge.log_format = :json
end

# after
Rails.application.configure do
  config.lograge.enabled = true
  config.lograge.formatter = Lograge::Formatters::Json.new
end
Defensive patterns

Strategy: validation

Validate before calling

# Fail fast at boot or in CI if the deprecated key is still set:
if Rails.application.config.lograge.log_format
  abort 'config.lograge.log_format is deprecated and will be ignored in lograge 1.0 — set config.lograge.formatter instead'
end
# One-liner for CI: bin/rails runner 'abort "deprecated lograge log_format set" if Rails.application.config.lograge.log_format'

Prevention

When it happens

Trigger: Booting any Rails process (server, console, rake task, rails runner) where an initializer sets config.lograge.log_format to a truthy value — typically :json, :raw, or :lograge — in config/initializers/lograge.rb, config/application.rb, or config/environments/production.rb. The lograge railtie runs support_deprecated_config during initialization (lib/lograge.rb:216) and calls deprecator.warn with the message plus a caller backtrace pointing at your initializer.

Common situations: Initializers copied from older blog posts or other apps written against pre-formatter lograge; apps upgrading lograge across the release that introduced config.lograge.formatter; production apps whose log ingest (ELK, Fluentd, Datadog) depends on JSON lines and would silently lose structured output after a future upgrade to lograge 1.0; noisy CI logs when ActiveSupport deprecation behaviors are set to :log or :stderr.


AI-assisted analysis of roidrage/lograge@e5caed7775 (2026-08-23). Data as JSON: /api/errors/03fd56f14e1a3ee5. Report an issue: GitHub.