在一个新的rails 7.1.2应用程序中,可以在config/environments/production.rb
中找到以下几行:
config.logger = ActiveSupport::Logger.new(STDOUT)
.tap { |logger| logger.formatter = ::Logger::Formatter.new }
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
这会告诉Rails记录器将记录到STDOUT
.
我想配置它,让它也记录到log/production.log
,但我无论如何也想不出来……
In this article by Fly.io它说要添加以下几行:
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)
但这些说明似乎是针对Rails<;7.1的,因为我收到了ActiveSupport::Logger:Class`的错误NoMethodError: undefined method
Broadcast‘.
如何在Rails 7.1中实现这一点?