跳至内容 跳至搜索
命名空间
方法
L
N
包含模块

类公共方法

logger_outputs_to?(logger, *sources)

如果日志目标与其中一个源匹配,则返回 true

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
# 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

new(*args, **kwargs)

# File activesupport/lib/active_support/logger.rb, line 33
def initialize(*args, **kwargs)
  super
  @formatter ||= SimpleFormatter.new
end

normalize_sources(sources)

# File activesupport/lib/active_support/logger.rb, line 47
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