Action Cable Connection TaggedLoggerProxy

Allows the use of per-connection tags against the server logger. This wouldn’t work using the traditional ActiveSupport::TaggedLogging enhanced Rails.logger, as that logger will reset the tags between requests. The connection is long-lived, so it needs its own set of tags for its independent duration.

Methods

Attributes

[R] tags

Class Public methods

new(logger, tags:)

📝 Source code
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 13
      def initialize(logger, tags:)
        @logger = logger
        @tags = tags.flatten
      end
🔎 See on GitHub

Instance Public methods

add_tags(*tags)

📝 Source code
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 18
      def add_tags(*tags)
        @tags += tags.flatten
        @tags = @tags.uniq
      end
🔎 See on GitHub

tag(logger, &block)

📝 Source code
# 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
🔎 See on GitHub

Instance Private methods

log(type, message, &block)

📝 Source code
# 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
🔎 See on GitHub