Skip to Content Skip to Search

class ActiveSupport::Logger

Inherits From

Public class methods

Returns true if the logger destination matches one of the sources

logger = Logger.new(STDOUT)
ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
# => true

logger = Logger.new('/var/log/rails.log')
ActiveSupport::Logger.logger_outputs_to?(logger, '/var/log/rails.log')
# => true
Source code GitHub
# File activesupport/lib/active_support/logger.rb, line 20
def self.logger_outputs_to?(logger, *sources)
  loggers = if logger.is_a?(BroadcastLogger)
    logger.broadcasts
  else
    [logger]
  end

  logdevs = loggers.map { |logger| logger.instance_variable_get(:@logdev) }
  logger_sources = logdevs.filter_map { |logdev| logdev.try(:filename) || logdev.try(:dev) }

  normalize_sources(sources).intersect?(normalize_sources(logger_sources))
end
Source code GitHub
# File activesupport/lib/active_support/logger.rb, line 33
def initialize(*args, **kwargs)
  super
  @formatter ||= SimpleFormatter.new
end

Namespace

Definition files