Sha256: 77db072f58841d765d8491942732e93ba536023d3aaaeb3589f6834033979ee0

Contents?: true

Size: 972 Bytes

Versions: 89

Compression:

Stored size: 972 Bytes

Contents

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

89 entries across 89 versions & 1 rubygems

Version Path
copy_tuner_client-0.1.1.beta15 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta14 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta13 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta12 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta11 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta10 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.15 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta9 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta8 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta7 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta6 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta5 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.14 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta4 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta3 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta2 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.1.beta lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.1.0.beta lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.12 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.11 lib/copy_tuner_client/prefixed_logger.rb