Action Cable Connection TaggedLoggerProxy¶ ↑
允许使用每个连接的标签来记录服务器日志。这在使用传统的 ActiveSupport::TaggedLogging 增强的 Rails.logger 时是行不通的,因为该日志记录器会在请求之间重置标签。连接是长期存在的,因此它需要自己的标签集来独立存在。
方法
Attributes
| [R] | tags |
类公共方法
new(logger, tags:) 链接
来源: 显示 | 在 GitHub 上
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 16 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 26 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 42 def log(type, message, &block) # :doc: tag(@logger) { @logger.send type, message, &block } end