Sha256: 1cfd80a9d1ce2051c465e1ee69c2097bf9d0e8b63b13bcfb421db2192544a862

Contents?: true

Size: 883 Bytes

Versions: 2

Compression:

Stored size: 883 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

    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

2 entries across 2 versions & 1 rubygems

Version Path
copycopter_client-1.0.0.beta2 lib/copycopter_client/prefixed_logger.rb
copycopter_client-1.0.0.beta1 lib/copycopter_client/prefixed_logger.rb