跳至内容 跳至搜索

Action Cable 连接 TaggedLoggerProxy

允许针对服务器记录器使用每个连接的标记。这无法使用传统的 ActiveSupport::TaggedLogging 增强 Rails.logger 实现,因为该记录器将在请求之间重置标记。连接是长期的,因此它需要自己的标记集以独立持续。

方法
A
L
N
T

属性

[R] tags

类公共方法

new(logger, tags:)

# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 13
def initialize(logger, tags:)
  @logger = logger
  @tags = tags.flatten
end

实例公共方法

add_tags(*tags)

# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 18
def add_tags(*tags)
  @tags += tags.flatten
  @tags = @tags.uniq
end

tag(logger, &block)

# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 23
def tag(logger, &block)
  if logger.respond_to?(:tagged)
    current_tags = tags - logger.formatter.current_tags
    logger.tagged(*current_tags, &block)
  else
    yield
  end
end

实例私有方法

log(type, message, &block)

# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 39
def log(type, message, &block) # :doc:
  tag(@logger) { @logger.send type, message, &block }
end