Sha256: f57a53e7838e922a46e85f0f08fb0ef1cfb2021db6de144633056fb0f34103ea

Contents?: true

Size: 709 Bytes

Versions: 8

Compression:

Stored size: 709 Bytes

Contents

# Wrap the Logger object with convenience methods.
class CarrotRpc::TaggedLog
  attr_reader :logger, :tags

  def initialize(logger:, tags:)
    @logger = logger
    @tags = *tags
  end

  def level
    logger.level
  end

  def level=(level)
    logger.level = level
  end

  # Dyanmically define logger methods with a tagged reference. Makes filtering of logs possible.
  %i(debug info warn error fatal unknown).each do |level|
    define_method(level) do |msg = nil, &block|
      logger.tagged(tags) { logger.send(level, msg || block.call) }
    end
  end

  delegate :tagged, to: :logger

  def with_correlation_id(correlation_id, &block)
    tagged("correlation_id=#{correlation_id}", &block)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
carrot_rpc-1.2.1 lib/carrot_rpc/tagged_log.rb
carrot_rpc-1.2.0 lib/carrot_rpc/tagged_log.rb
carrot_rpc-1.1.0 lib/carrot_rpc/tagged_log.rb
carrot_rpc-1.0.0 lib/carrot_rpc/tagged_log.rb
carrot_rpc-0.8.0 lib/carrot_rpc/tagged_log.rb
carrot_rpc-0.7.1 lib/carrot_rpc/tagged_log.rb
carrot_rpc-0.7.0 lib/carrot_rpc/tagged_log.rb
carrot_rpc-0.6.0 lib/carrot_rpc/tagged_log.rb