DEV: Route Sidekiq logs to Rails logger (#15817)

Most of our logging goes through Rails.logger, and therefore appears in Logster at `/logs` on a site. The Sidekiq logger was bypassing this and writing directly to STDERR.

Unfortunately it's not possible to do `Sidekiq.logger = Rails.logger` because `Sidekiq#logger=` applies a number of patches to the logger instance, causing our whole logging system to break.

Instead, this commit adds a dedicated Logger instance with no output, which is then patched to forward all messages directly to `Rails.logger`
This commit is contained in:
David Taylor
2022-02-04 16:28:20 +00:00
committed by GitHub
parent 0dfaaf49a5
commit fe5bfc8d3b
2 changed files with 11 additions and 10 deletions

View File

@@ -27,11 +27,6 @@ class Demon::Sidekiq < ::Demon::Base
puts "Loading Sidekiq in process id #{Process.pid}"
require 'sidekiq/cli'
# CLI will close the logger, if we have one set we can be in big
# trouble, if STDOUT is closed in our process all sort of weird
# will ensue, resetting the logger ensures it will reinit correctly
# parent process is in charge of the file anyway.
Sidekiq.logger = Sidekiq::Logger.new(STDERR, level: Logger::WARN)
cli = Sidekiq::CLI.instance
# Unicorn uses USR1 to indicate that log files have been rotated