Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overriding previously defined custom options for lograge #750

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion elasticsearch-rails/lib/elasticsearch/rails/lograge.rb
Expand Up @@ -29,8 +29,18 @@ class Railtie < ::Rails::Railtie
include Elasticsearch::Rails::Instrumentation::ControllerRuntime
end

previous_lograge_custom_options = config.lograge.custom_options
config.lograge.custom_options = lambda do |event|
{ es: event.payload[:elasticsearch_runtime].to_f.round(2) }
previous_lograge_custom_options_hash = if previous_lograge_custom_options
if previous_lograge_custom_options.respond_to?(:call)
previous_lograge_custom_options.call(event)
else
previous_lograge_custom_options
end
else
{}
end
previous_lograge_custom_options_hash.merge(es: event.payload[:elasticsearch_runtime].to_f.round(2))
end
end
end
Expand Down