class ActionCable::Connection::TaggedLoggerProxy

Parent:
Object

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.

Attributes

tags[R]

Public Class Methods

new(logger, tags:) Show source
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 9
def initialize(logger, tags))
  @logger = logger
  @tags = tags.flatten
end

Public Instance Methods

add_tags(*tags) Show source
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 14
def add_tags(*tags)
  @tags += tags.flatten
  @tags = @tags.uniq
end
tag(logger) { || ... } Show source
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 19
def tag(logger)
  if logger.respond_to?(:tagged)
    current_tags = tags - logger.formatter.current_tags
    logger.tagged(*current_tags) { yield }
  else
    yield
  end
end

Protected Instance Methods

log(type, message) Show source
# File actioncable/lib/action_cable/connection/tagged_logger_proxy.rb, line 35
def log(type, message)
  tag(@logger) { @logger.send type, message }
end

© 2004–2018 David Heinemeier Hansson
Licensed under the MIT License.