aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/logger.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/logger.rb')
-rw-r--r--activesupport/lib/active_support/logger.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb
index 520268b244..7626b28108 100644
--- a/activesupport/lib/active_support/logger.rb
+++ b/activesupport/lib/active_support/logger.rb
@@ -5,18 +5,27 @@ module ActiveSupport
class Logger < ::Logger
include LoggerSilence
- attr_accessor :broadcast_messages
+ # Returns true if the logger destination matches one of the sources
+ #
+ # logger = Logger.new(STDOUT)
+ # ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
+ # # => true
+ def self.logger_outputs_to?(logger, *sources)
+ logdev = logger.instance_variable_get("@logdev")
+ logger_source = logdev.dev if logdev.respond_to?(:dev)
+ sources.any? { |source| source == logger_source }
+ end
# Broadcasts logs to multiple loggers.
def self.broadcast(logger) # :nodoc:
Module.new do
define_method(:add) do |*args, &block|
- logger.add(*args, &block) if broadcast_messages
+ logger.add(*args, &block)
super(*args, &block)
end
define_method(:<<) do |x|
- logger << x if broadcast_messages
+ logger << x
super(x)
end
@@ -45,7 +54,6 @@ module ActiveSupport
def initialize(*args)
super
@formatter = SimpleFormatter.new
- @broadcast_messages = true
after_initialize if respond_to? :after_initialize
end