Sha256: d68aba1fbccdd1958bc699d8e7f7d059de289e7f05c8fb30087cba5dcab30b9b

Contents?: true

Size: 973 Bytes

Versions: 19

Compression:

Stored size: 973 Bytes

Contents

module CopycopterClient
  class PrefixedLogger
    attr_reader :prefix, :original_logger

    def initialize(prefix, logger)
      @prefix          = prefix
      @original_logger = logger
    end

    def info(message = nil, &block)
      log(:info, message, &block)
    end

    def debug(message = nil, &block)
      log(:debug, message, &block)
    end

    def warn(message = nil, &block)
      log(:warn, message, &block)
    end

    def error(message = nil, &block)
      log(:error, message, &block)
    end

    def fatal(message = nil, &block)
      log(:fatal, message, &block)
    end

    def flush
      original_logger.flush if original_logger.respond_to?(:flush)
    end

    private

    def log(severity, message, &block)
      prefixed_message = "#{prefix} #{thread_info} #{message}"
      original_logger.send(severity, prefixed_message, &block)
    end

    def thread_info
      "[P:#{Process.pid}] [T:#{Thread.current.object_id}]"
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
copycopter_client-2.0.1 lib/copycopter_client/prefixed_logger.rb
copycopter_client-2.0.0 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.1.2 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.1.1 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.1.0 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.4 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.3 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.2 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.1 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta11 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta10 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta9 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta8 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta7 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta6 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta5 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta4 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta3 lib/copycopter_client/prefixed_logger.rb