DEV: Remove noise from Rails::Rack::Logger after Rails 7.1 upgrade (#27731)

This commit monkey patches `Rails::Rack::Logger` to not log reqeust
information like `Started GET "/service-worker.js" for 127.0.0.1 at 2024-07-05 15:28:12 +0800`
when lograge is enabled. This was previously excluded by a monkey patch
in the `lograge` gem but that monkey patch has since broke and the gem
is unmaintained.
This commit is contained in:
Alan Guo Xiang Tan 2024-07-08 08:42:58 +08:00 committed by GitHub
parent 21b62f7894
commit 5ca2c8b8ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,6 +13,11 @@ Rails.application.config.to_prepare do
Rails.application.configure do
config.lograge.enabled = true
# Monkey patch Rails::Rack::Logger#logger to silence its logs.
# The `lograge` gem is supposed to do this but it broke after we upgraded to Rails 7.1.
# This patch is a temporary workaround until we find a proper fix.
Rails::Rack::Logger.prepend(Module.new { def logger = (@logger ||= Logger.new(IO::NULL)) })
Lograge.ignore(
lambda do |event|
# this is our hijack magic status,