From 67f5122ba6de9d7d669e5d5ccb2c8fdb119a6f0a Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 21 May 2025 04:50:36 -0400 Subject: [PATCH] Use `ActiveSupport::TaggedLogging.logger` shorthand to set logger in production env (#34746) --- config/environments/production.rb | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 6d4c30cd20..08923ca108 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -52,17 +52,14 @@ Rails.application.configure do }, } - # Log to STDOUT by default - config.logger = ActiveSupport::Logger.new($stdout) - .tap { |logger| logger.formatter = ::Logger::Formatter.new } - .then { |logger| ActiveSupport::TaggedLogging.new(logger) } + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = Logger::Formatter.new - # Prepend all log lines with the following tags. + # Log to STDOUT with the current request id as a default log tag. config.log_tags = [:request_id] + config.logger = ActiveSupport::TaggedLogging.logger($stdout, formatter: config.log_formatter) - # "info" includes generic and useful information about system operation, but avoids logging too much - # information to avoid inadvertent exposure of personally identifiable information (PII). If you - # want to log everything, set the level to "debug". + # Change to "debug" to log everything (including potentially personally-identifiable information!) config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info') # Use a different cache store in production. @@ -90,9 +87,6 @@ Rails.application.configure do # Don't log any deprecations. config.active_support.report_deprecations = false - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new - # Better log formatting config.lograge.enabled = true