class ActionCable::Connection::TaggedLoggerProxy
The connection is long-lived, so it needs its own set of tags for its independent duration.
ActiveSupport::TaggedLogging enhanced Rails.logger, as that logger will reset the tags between requests.
Allows the use of per-connection tags against the server logger. This wouldn’t work using the traditional
def add_tags(*tags)
def add_tags(*tags) @tags += tags.flatten @tags = @tags.uniq end
def initialize(logger, tags:)
def initialize(logger, tags:) @logger = logger @tags = tags.flatten end
def log(type, message) # :doc:
def log(type, message) # :doc: tag(@logger) { @logger.send type, message } end
def tag(logger, &block)
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