Rescue from errors when trying to append custom payloads to lograge output.

This commit is contained in:
Guo Xiang Tan 2017-12-08 08:30:48 +08:00
parent cff9b8846d
commit 2ff3444568
1 changed files with 36 additions and 31 deletions

View File

@ -8,19 +8,20 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["
Rails.application.configure do
config.lograge.enabled = true
# Seeing RuntimeError (Missing rack.input)
# for: `/topics/timings`
#
#
# config.lograge.custom_payload do |controller|
# username = controller.try(:current_user)&.username rescue nil
# {
# ip: controller.request.remote_ip,
# username: username,
# }
# end
config.lograge.custom_payload do |controller|
begin
{
ip: controller.request.remote_ip,
username: controller.current_user&.username,
}
rescue => e
Rails.logger.warn("Failed to append custom payload: #{e.message}\n#{e.backtrace.join("\n")}")
{}
end
end
config.lograge.custom_options = lambda do |event|
begin
exceptions = %w(controller action format id)
params = event.payload[:params].except(*exceptions)
@ -48,6 +49,10 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["
end
output
rescue => e
Rails.logger.warn("Failed to append custom options: #{e.message}\n#{e.backtrace.join("\n")}")
{}
end
end
if ENV["LOGSTASH_URI"]