2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-12 10:31:28 +02:00
|
|
|
Rails.application.configure do
|
|
|
|
config.lograge.formatter = Lograge::Formatters::Logstash.new
|
|
|
|
config.lograge.base_controller_class = ['ActionController::Base', 'Manager::ApplicationController']
|
|
|
|
|
|
|
|
# This will allow to override custom options from environement file
|
|
|
|
# injected by ansible.
|
|
|
|
if !config.lograge.custom_options
|
|
|
|
config.lograge.custom_options = lambda do |event|
|
2023-11-08 12:19:03 +01:00
|
|
|
hash = {
|
2018-08-12 10:31:28 +02:00
|
|
|
type: 'tps',
|
2018-08-22 18:10:26 +02:00
|
|
|
source: ENV['SOURCE'],
|
2018-08-14 22:39:34 +02:00
|
|
|
tags: ['request', event.payload[:exception] ? 'exception' : nil].compact,
|
2023-03-15 14:44:31 +01:00
|
|
|
process: {
|
|
|
|
pid: Process.pid
|
|
|
|
}
|
2023-11-08 12:19:03 +01:00
|
|
|
}
|
|
|
|
|
2023-11-13 15:52:09 +01:00
|
|
|
hash.merge!(event.payload[:to_log]) if event.payload.key?(:to_log)
|
2023-11-08 12:19:03 +01:00
|
|
|
|
|
|
|
hash.compact
|
2018-08-12 10:31:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
config.lograge.custom_payload do |controller|
|
|
|
|
{
|
2018-08-13 16:40:16 +02:00
|
|
|
xhr: !!controller&.request&.xhr?
|
2018-08-12 10:31:28 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
config.lograge.keep_original_rails_log = true
|
2018-12-24 16:32:23 +01:00
|
|
|
config.lograge.logger = ActiveSupport::Logger.new(Rails.root.join('log', "logstash_#{Rails.env}.log"))
|
2023-06-21 17:11:32 +02:00
|
|
|
config.lograge.ignore_actions = ['PingController#index']
|
2023-05-03 13:18:09 +02:00
|
|
|
end
|
2018-08-14 22:39:34 +02:00
|
|
|
|
2023-05-03 13:18:09 +02:00
|
|
|
Rails.application.config.after_initialize do |app|
|
|
|
|
if app.config.lograge.enabled
|
2021-10-07 13:05:27 +02:00
|
|
|
ActiveJob::ApplicationLogSubscriber.attach_to(:active_job)
|
2018-08-14 22:39:34 +02:00
|
|
|
end
|
2018-08-12 10:31:28 +02:00
|
|
|
end
|