In a new Rails 7.1.2 app, the following lines can be found in config/environments/production.rb
:
config.logger = ActiveSupport::Logger.new(STDOUT)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
This tells the Rails logger to log to STDOUT
.
I would like to configure it so that it ALSO logs to log/production.log
, but I can't for the life of me figure it out...
In this article by Fly.io it says to add these lines:
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
volume_logger = ActiveSupport::Logger.new("/logs/production.log", 3)
logger = logger.extend ActiveSupport::Logger.broadcast(volume_logger)
But it seems like these instructions are for Rails < 7.1, since I get the error NoMethodError: undefined method
broadcast' for ActiveSupport::Logger:Class`.
How can I do this in Rails 7.1?