Sha256: 30f7ca5fb64af98f3a265e58c3153627c70b537154929251e087b3f4e25c0dee

Contents?: true

Size: 536 Bytes

Versions: 2

Compression:

Stored size: 536 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|
      logger.tagged(tags) { logger.send(level, msg) }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carrot_rpc-0.2.3 lib/carrot_rpc/tagged_log.rb
carrot_rpc-0.2.3.pre lib/carrot_rpc/tagged_log.rb