Sha256: cb11a7ccaa15d719209f00e263d3ff24a75558c643d2fdefde74ee59e0c5df31

Contents?: true

Size: 1.15 KB

Versions: 108

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
    # <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

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

Version data entries

108 entries across 108 versions & 8 rubygems

Version Path
actioncable-6.1.4.2 lib/action_cable/connection/tagged_logger_proxy.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/actioncable-6.1.4.1/lib/action_cable/connection/tagged_logger_proxy.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/actioncable-6.1.4.1/lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.4.1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.0.4.1 lib/action_cable/connection/tagged_logger_proxy.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/actioncable-6.1.4/lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.4 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.0.4 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.2.6 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.0.3.7 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.3.2 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.2.4.6 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.3.1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.0.3.6 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.2.5 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.3 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.2.1 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.0.3.5 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-5.2.4.5 lib/action_cable/connection/tagged_logger_proxy.rb
actioncable-6.1.2 lib/action_cable/connection/tagged_logger_proxy.rb