EXPERIMENTAL: Allow Logstash formatter to be enable for lograge logs.

This commit is contained in:
Guo Xiang Tan 2017-11-01 08:37:11 +08:00
parent 076df104dc
commit d888d3c54c
3 changed files with 11 additions and 1 deletions

View File

@ -173,6 +173,7 @@ gem 'memory_profiler', require: false, platform: :mri
gem 'cppjieba_rb', require: false gem 'cppjieba_rb', require: false
gem 'lograge', require: false gem 'lograge', require: false
gem 'logstash-event', require: false
gem 'logster' gem 'logster'
gem 'sassc', require: false gem 'sassc', require: false

View File

@ -155,6 +155,7 @@ GEM
activesupport (>= 4, < 5.2) activesupport (>= 4, < 5.2)
railties (>= 4, < 5.2) railties (>= 4, < 5.2)
request_store (~> 1.0) request_store (~> 1.0)
logstash-event (1.2.02)
logster (1.2.8) logster (1.2.8)
loofah (2.1.1) loofah (2.1.1)
crass (~> 1.0.2) crass (~> 1.0.2)
@ -438,6 +439,7 @@ DEPENDENCIES
http_accept_language (~> 2.0.5) http_accept_language (~> 2.0.5)
listen listen
lograge lograge
logstash-event
logster logster
lru_redux lru_redux
mail mail

View File

@ -7,11 +7,18 @@ if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["
config.lograge.custom_options = lambda do |event| config.lograge.custom_options = lambda do |event|
exceptions = %w(controller action format id) exceptions = %w(controller action format id)
params = event.payload[:params].except(*exceptions)
params[:files].map!(&:headers) if params[:files]
output = { output = {
params: event.payload[:params].except(*exceptions), params: params,
database: RailsMultisite::ConnectionManagement.current_db, database: RailsMultisite::ConnectionManagement.current_db,
time: event.time, time: event.time,
} }
end end
if ENV["LOGSTASH_FORMATTER"]
config.lograge.formatter = Lograge::Formatters::Logstash.new
end
end end
end end