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.0.9 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.8 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.7 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.6 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.5 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.4 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.3 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.2 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.0.1 lib/copy_tuner_client/prefixed_logger.rb