Sha256: 5a64d0364b58875cc108a5a26b35b578fd6cfb027cb288344591986734f7b602

Contents?: true

Size: 1.11 KB

Versions: 35

Compression:

Stored size: 1.11 KB

Contents

module ActionCable
  module Connection
    # Allows the use of per-connection tags against the server logger. This wouldn't work using the traditional
    # <tt>ActiveSupport::TaggedLogging</tt> 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)
        if logger.respond_to?(:tagged)
          current_tags = tags - logger.formatter.current_tags
          logger.tagged(*current_tags) { yield }
        else
          yield
        end
      end

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

      protected
        def log(type, message)
          tag(@logger) { @logger.send type, message }
        end
    end
  end
end

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
actioncable-5.0.7.2 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.7.1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.7 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.6 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.6.rc1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.5 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.5.rc2 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.5.rc1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.4 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.4.rc1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.3 lib/action_cable/connection/tagged_logger_proxy.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actioncable-5.0.2/lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.2 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.0.2.rc1 lib/action_cable/connection/tagged_logger_proxy.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.1/lib/action_cable/connection/tagged_logger_proxy.rb