Sha256: 0627bbff3a23123847f909cc572995b7e648a5bb813a59e663da4e3d22f2b4c7

Contents?: true

Size: 1.15 KB

Versions: 24

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module ActionCable
  module Connection
    # 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.
    class TaggedLoggerProxy
      attr_reader :tags

      def initialize(logger, tags:)
        @logger = logger
        @tags = tags.flatten
      end

      def add_tags(*tags)
        @tags += tags.flatten
        @tags = @tags.uniq
      end

      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

      %i( debug info warn error fatal unknown ).each do |severity|
        define_method(severity) do |message|
          log severity, message
        end
      end

      private
        def log(type, message) # :doc:
          tag(@logger) { @logger.send type, message }
        end
    end
  end
end

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
actioncable-7.0.8.7 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.8.6 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.8.5 lib/action_cable/connection/tagged_logger_proxy.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/actioncable-7.0.8.4/lib/action_cable/connection/tagged_logger_proxy.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/connection/tagged_logger_proxy.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/connection/tagged_logger_proxy.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/actioncable-7.0.5.1/lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.8.4 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.8.1 lib/action_cable/connection/tagged_logger_proxy.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/actioncable-7.0.3.1/lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.8 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.7.2 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.7.1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.7 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.6 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.5.1 lib/action_cable/connection/tagged_logger_proxy.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/actioncable-7.0.3.1/lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.5 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.4.3 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-7.0.4.2 lib/action_cable/connection/tagged_logger_proxy.rb