Sha256: 0e0663d3107ef51b2b7649340ee54f67c18d595a4f157fecc429648821196549

Contents?: true

Size: 562 Bytes

Versions: 4

Compression:

Stored size: 562 Bytes

Contents

require 'logger'

module ConsulStockpile
  class Logger
    class << self
      %i[debug info warn error fatal].each do |sym|
        define_method(sym) do |message|
          logger.send(sym, "#{Thread.current[:logger_tag]}#{message}")
        end
      end
    end

    def self.tagged(tag)
      existing_tag = Thread.current[:logger_tag]
      Thread.current[:logger_tag] = "[#{tag}] "
      yield
    ensure
      Thread.current[:logger_tag] = existing_tag
    end

    def self.logger
      Thread.current[:logger] = ::Logger.new(STDOUT)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
consul_stockpile-0.1.5 lib/consul_stockpile/logger.rb
consul_stockpile-0.1.2 lib/consul_stockpile/logger.rb
consul_stockpile-0.1.1 lib/consul_stockpile/logger.rb
consul_stockpile-0.1.0 lib/consul_stockpile/logger.rb