-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Problem
Custom fields added via config.integrations.lograge_custom_options are collected but not included in the final log output.
Reproduction
LogStruct.configure do |config|
config.integrations.enable_lograge = true
config.integrations.lograge_custom_options = ->(event, options) {
options[:user_id] = event.payload[:user_id]
}
endExpected: {"source":"rails","event":"request","user_id":"abc-123",...}
Actual: {"src":"rails","evt":"request",...} (no user_id)
Root Cause
In lib/log_struct/integrations/lograge.rb, the formatter creates Log::Request.new(...) with only hardcoded fields (lines 40-65). Custom options added to the data hash are ignored because Log::Request only extracts specific fields.
Additionally, Log::Request has source_ip, user_agent, and request_id fields, but the formatter does not populate them from data even though lograge_default_options adds them.
Workaround
Disable LogStruct's lograge integration and configure Lograge directly with a dedicated STDOUT logger to bypass LogStruct's Rails.logger interception:
config.integrations.enable_lograge = false
# In a separate initializer:
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.logger = ActiveSupport::Logger.new($stdout)
config.lograge.custom_options = ->(event) { { user_id: event.payload[:user_id] }.compact }Environment
- logstruct: 0.1.7
- Rails: 8.1