From afdd31473d3276d1e7d91950d27ef1a622659bf6 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 27 Oct 2017 23:31:17 +0800 Subject: [PATCH] Add type when shipping logs to logstash. --- config/initializers/100-lograge.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/config/initializers/100-lograge.rb b/config/initializers/100-lograge.rb index e8b09855f01..d387630de32 100644 --- a/config/initializers/100-lograge.rb +++ b/config/initializers/100-lograge.rb @@ -4,16 +4,21 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV[" Rails.application.configure do config.lograge.enabled = true + logstash_uri = ENV["LOGSTASH_URI"].present? + config.lograge.custom_options = lambda do |event| exceptions = %w(controller action format id) - { + output = { params: event.payload[:params].except(*exceptions), - type: :rails + database: RailsMultisite::ConnectionManagement.current_db } + + output[:type] = :rails if logstash_uri + output end - if (logstash_uri = ENV["LOGSTASH_URI"].present?) + if logstash_uri require 'logstash-logger' config.lograge.formatter = Lograge::Formatters::Logstash.new