Sha256: f97d9383f0e351b47e9170541fdeb7323993af7a59e5d691b4c27956c02035f3

Contents?: true

Size: 676 Bytes

Versions: 20

Compression:

Stored size: 676 Bytes

Contents

require 'logger'

module Shipitron
  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

    def self.level
      logger.level
    end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
shipitron-1.4.1 lib/shipitron/logger.rb
shipitron-1.4.0 lib/shipitron/logger.rb
shipitron-1.3.2 lib/shipitron/logger.rb
shipitron-1.3.1 lib/shipitron/logger.rb
shipitron-1.3.0 lib/shipitron/logger.rb
shipitron-1.2.1 lib/shipitron/logger.rb
shipitron-1.2.0 lib/shipitron/logger.rb
shipitron-1.1.0 lib/shipitron/logger.rb
shipitron-1.0.1 lib/shipitron/logger.rb
shipitron-1.0.0 lib/shipitron/logger.rb
shipitron-0.4.1 lib/shipitron/logger.rb
shipitron-0.4.0 lib/shipitron/logger.rb
shipitron-0.3.5 lib/shipitron/logger.rb
shipitron-0.3.4 lib/shipitron/logger.rb
shipitron-0.3.3 lib/shipitron/logger.rb
shipitron-0.3.1 lib/shipitron/logger.rb
shipitron-0.3.0 lib/shipitron/logger.rb
shipitron-0.2.2 lib/shipitron/logger.rb
shipitron-0.2.1 lib/shipitron/logger.rb
shipitron-0.2.0 lib/shipitron/logger.rb