diff --git a/Gemfile b/Gemfile index 83109b0ff20..befe82d7750 100644 --- a/Gemfile +++ b/Gemfile @@ -172,7 +172,8 @@ gem 'memory_profiler', require: false, platform: :mri gem 'cppjieba_rb', require: false -gem 'lograge' +gem 'lograge', require: false +gem 'logstash-logger', require: false gem 'logster' gem 'sassc', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 59bc9e2574c..506f502ea2f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -155,6 +155,9 @@ GEM activesupport (>= 4, < 5.2) railties (>= 4, < 5.2) request_store (~> 1.0) + logstash-event (1.2.02) + logstash-logger (0.25.1) + logstash-event (~> 1.2) logster (1.2.8) loofah (2.1.1) crass (~> 1.0.2) @@ -438,6 +441,7 @@ DEPENDENCIES http_accept_language (~> 2.0.5) listen lograge + logstash-logger logster lru_redux mail diff --git a/config/initializers/100-lograge.rb b/config/initializers/100-lograge.rb index cdd678e7f69..e8b09855f01 100644 --- a/config/initializers/100-lograge.rb +++ b/config/initializers/100-lograge.rb @@ -1,10 +1,27 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["ENABLE_LOGRAGE"] + require 'lograge' + Rails.application.configure do config.lograge.enabled = true config.lograge.custom_options = lambda do |event| exceptions = %w(controller action format id) - { params: event.payload[:params].except(*exceptions) } + + { + params: event.payload[:params].except(*exceptions), + type: :rails + } + end + + if (logstash_uri = ENV["LOGSTASH_URI"].present?) + require 'logstash-logger' + + config.lograge.formatter = Lograge::Formatters::Logstash.new + + config.lograge.logger = LogStashLogger.new( + type: :tcp, + uri: logstash_uri + ) end end end