diff options
author | Nate Smith <nwjsmith@gmail.com> | 2015-12-14 17:27:03 -0500 |
---|---|---|
committer | Nate Smith <nwjsmith@gmail.com> | 2015-12-16 16:08:56 -0500 |
commit | e12ffb76ffcedd150e7d0c3dc4f93472aa4790cb (patch) | |
tree | 504153f7aa2365a26403b5fdea14104bc53eed83 /activesupport/lib/active_support | |
parent | 87e44814679625b4d8093aea253fe49e23f2c1b4 (diff) | |
download | rails-e12ffb76ffcedd150e7d0c3dc4f93472aa4790cb.tar.gz rails-e12ffb76ffcedd150e7d0c3dc4f93472aa4790cb.tar.bz2 rails-e12ffb76ffcedd150e7d0c3dc4f93472aa4790cb.zip |
Add Logger option to disable message broadcasts
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
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/logger.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/logger_silence.rb | 5 |
2 files changed, 8 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb index 33fccdcf95..82117a64d2 100644 --- a/activesupport/lib/active_support/logger.rb +++ b/activesupport/lib/active_support/logger.rb @@ -1,4 +1,3 @@ -require 'active_support/core_ext/module/attribute_accessors' require 'active_support/logger_silence' require 'logger' @@ -6,16 +5,18 @@ module ActiveSupport class Logger < ::Logger include LoggerSilence + attr_accessor :broadcast_messages + # Broadcasts logs to multiple loggers. def self.broadcast(logger) # :nodoc: Module.new do define_method(:add) do |*args, &block| - logger.add(*args, &block) + logger.add(*args, &block) if broadcast_messages super(*args, &block) end define_method(:<<) do |x| - logger << x + logger << x if broadcast_messages super(x) end @@ -44,6 +45,7 @@ module ActiveSupport def initialize(*args) super @formatter = SimpleFormatter.new + @broadcast_messages = true end # Simple formatter which only displays the message. diff --git a/activesupport/lib/active_support/logger_silence.rb b/activesupport/lib/active_support/logger_silence.rb index a8efdef944..7d92256f24 100644 --- a/activesupport/lib/active_support/logger_silence.rb +++ b/activesupport/lib/active_support/logger_silence.rb @@ -1,8 +1,9 @@ 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 @@ -21,4 +22,4 @@ module LoggerSilence yield self end end -end
\ No newline at end of file +end |