mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
This PR addresses several issues related to logging: - Enabling Lograge broke certain non-API URLs, such as password reset. This occurred due to the user ID tagging we had in Lograge, which has now been limited to API pages only. - Disabled the start and done logs in Sidekiq. - Investigated why Sidekiq logs weren’t being output as JSON. This is due to the use of ActiveJob instead of Sidekiq for the job base classes. **Potential Options for Converting ActiveJob Logs to JSON:** - https://glozer.rocks/ojb - https://learnedreverie.medium.com/activejob-logs-as-json-6912403d8c81 - https://github.com/roidrage/lograge/pull/226
31 lines
1.1 KiB
Ruby
31 lines
1.1 KiB
Ruby
if ActiveModel::Type::Boolean.new.cast(ENV.fetch('LOGRAGE_ENABLED', false)).present?
|
|
require 'lograge'
|
|
|
|
Rails.application.configure do
|
|
config.lograge.enabled = true
|
|
config.lograge.formatter = Lograge::Formatters::Json.new
|
|
config.lograge.custom_payload do |controller|
|
|
# We only need user_id for API requests
|
|
# might error out for other controller - ref: https://github.com/chatwoot/chatwoot/issues/6922
|
|
user_id = controller&.try(:current_user)&.id if controller.is_a?(Api::BaseController) && controller&.try(:current_user).is_a?(User)
|
|
{
|
|
host: controller.request.host,
|
|
remote_ip: controller.request.remote_ip,
|
|
user_id: user_id
|
|
}
|
|
end
|
|
|
|
config.lograge.custom_options = lambda do |event|
|
|
param_exceptions = %w[controller action format id]
|
|
{
|
|
params: event.payload[:params]&.except(*param_exceptions)
|
|
}
|
|
end
|
|
|
|
config.lograge.ignore_custom = lambda do |event|
|
|
# ignore update_presence events in log
|
|
return true if event.payload[:channel_class] == 'RoomChannel'
|
|
end
|
|
end
|
|
end
|