debian-mirror-gitlab/config/initializers/lograge.rb

39 lines
1.4 KiB
Ruby
Raw Normal View History

2017-09-10 17:25:29 +05:30
# Only use Lograge for Rails
unless Sidekiq.server?
filename = File.join(Rails.root, 'log', "#{Rails.env}_json.log")
Rails.application.configure do
config.lograge.enabled = true
# Store the lograge JSON files in a separate file
config.lograge.keep_original_rails_log = true
# Don't use the Logstash formatter since this requires logstash-event, an
# unmaintained gem that monkey patches `Time`
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.logger = ActiveSupport::Logger.new(filename)
# Add request parameters to log output
config.lograge.custom_options = lambda do |event|
2018-03-17 18:26:18 +05:30
params = event.payload[:params]
.except(*%w(controller action format))
.each_pair
.map { |k, v| { key: k, value: v } }
payload = {
2019-09-30 21:07:59 +05:30
time: Time.now.utc.iso8601(3),
2018-03-17 18:26:18 +05:30
params: params,
2017-09-10 17:25:29 +05:30
remote_ip: event.payload[:remote_ip],
user_id: event.payload[:user_id],
2018-11-20 20:47:30 +05:30
username: event.payload[:username],
2019-07-07 11:18:12 +05:30
ua: event.payload[:ua],
queue_duration: event.payload[:queue_duration]
2017-09-10 17:25:29 +05:30
}
2018-03-17 18:26:18 +05:30
2019-10-12 21:52:04 +05:30
::Gitlab::InstrumentationHelper.add_instrumentation_data(payload)
2019-07-07 11:18:12 +05:30
2018-11-08 19:23:39 +05:30
payload[:response] = event.payload[:response] if event.payload[:response]
2019-07-31 22:56:46 +05:30
payload[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id
2018-03-17 18:26:18 +05:30
payload
2017-09-10 17:25:29 +05:30
end
end
end