123456789_123456789_123456789_123456789_123456789_

Class: ActionCable::Connection::TaggedLoggerProxy

Relationships & Source Files
Inherits: Object
Defined in: actioncable/lib/action_cable/connection/tagged_logger_proxy.rb

Overview

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 Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(logger, tags:) ⇒ TaggedLoggerProxy

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/tagged_logger_proxy.rb', line 11

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

Instance Attribute Details

#tags (readonly)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/tagged_logger_proxy.rb', line 9

attr_reader :tags

Instance Method Details

#add_tags(*tags)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/tagged_logger_proxy.rb', line 16

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

#log(type, message) (private)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/tagged_logger_proxy.rb', line 37

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

#tag(logger)

[ GitHub ]

  
# File 'actioncable/lib/action_cable/connection/tagged_logger_proxy.rb', line 21

def tag(logger)
  if logger.respond_to?(:tagged)
    current_tags = tags - logger.formatter.current_tags
    logger.tagged(*current_tags) { yield }
  else
    yield
  end
end