-
-
Notifications
You must be signed in to change notification settings - Fork 301
Open
Description
Environment: Rails 5
Code:
config/environments/production.rb
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# loggly settings - lograge
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.custom_options = lambda do |event|
exceptions = %w(controller action format id)
{
params: event.payload[:params].except(*exceptions),
remote_ip: event.payload[:remote_ip],
uid: event.payload[:uid],
request_headers: event.payload[:request_headers],
time: event.time
}
end
config/initializers/lograge.rb
Rails.application.configure do
config.lograge.base_controller_class = 'ActionController::API'
end
The above is the result I saw in the Rails 5 environment on google cloud logs explorer.
However, after upgrading to Rails 6.1.7.2, the code remains unchanged, but the logs no longer appear on google cloud logs explorer as shown in the image. How should I adjust it?"
But when I configure it like this, the logs appear again. However, these logs are different from what I originally had. How can I adjust them to match my previous logs?
Code:
config/environments/production.rb
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
config.logger = ActiveSupport::TaggedLogging.new(logger)
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.custom_options = lambda do |event|
exceptions = %w(controller action format id)
{
method: event.payload[:method],
path: event.payload[:path],
controller: event.payload[:controller],
action: event.payload[:action],
status: event.payload[:status],
duration: event.duration.round(2),
view: event.payload[:view].to_f.round(2),
db: event.payload[:db].to_f.round(2),
params: event.payload[:params].except(*exceptions),
remote_ip: event.payload[:remote_ip],
uid: event.payload[:uid],
request_headers: event.payload[:request_headers],
time: event.time
}
end
end
Thank you for taking the time to read this, much appreciated
Metadata
Metadata
Assignees
Labels
No labels