class ActiveSupport::Logger
def self.logger_outputs_to?(logger, *sources)
ActiveSupport::Logger.logger_outputs_to?(logger, '/var/log/rails.log')
logger = Logger.new('/var/log/rails.log')
# => true
ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
logger = Logger.new(STDOUT)
Returns true if the logger destination matches one of the sources
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
def self.normalize_sources(sources)
def self.normalize_sources(sources) sources.map do |source| source = source.path if source.respond_to?(:path) source = File.realpath(source) if source.is_a?(String) && File.exist?(source) source end end
def initialize(*args, **kwargs)
def initialize(*args, **kwargs) super @formatter ||= SimpleFormatter.new end