Action Cable 连接 TaggedLoggerProxy
允许针对服务器记录器使用每个连接的标记。这无法使用传统的 ActiveSupport::TaggedLogging
增强 Rails.logger
实现,因为该记录器将在请求之间重置标记。连接是长期的,因此它需要自己的标记集以独立持续。
方法
属性
[R] | tags |
类公共方法
new(logger, tags:) 链接
来源:显示 | 在 GitHub 上
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 13 def initialize(logger, tags:) @logger = logger @tags = tags.flatten end
实例公共方法
tag(logger, &block) 链接
来源:显示 | 在 GitHub 上
# 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) 链接
来源:显示 | 在 GitHub 上
# 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