mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
e12ffb76ff
When setting the Rails logger to log to STDOUT, it would broadcast the log twice in development. This adds a setting that will prevent messages from being broadcast to multiple logs, while still allowing calls to `#close`, `#level=`, `#progname=`, and `#formatter=` to be broadcasted. Fixes #14769, #11415
25 lines
540 B
Ruby
25 lines
540 B
Ruby
require 'active_support/concern'
|
|
require 'active_support/core_ext/module/attribute_accessors'
|
|
|
|
module LoggerSilence
|
|
extend ActiveSupport::Concern
|
|
|
|
included do
|
|
cattr_accessor :silencer
|
|
self.silencer = true
|
|
end
|
|
|
|
# Silences the logger for the duration of the block.
|
|
def silence(temporary_level = Logger::ERROR)
|
|
if silencer
|
|
begin
|
|
old_logger_level, self.level = level, temporary_level
|
|
yield self
|
|
ensure
|
|
self.level = old_logger_level
|
|
end
|
|
else
|
|
yield self
|
|
end
|
|
end
|
|
end
|