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.19.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.18.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.17.1 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.16.3 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.16.2 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.16.1 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.16.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.15.1 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.15.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.14.2 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.14.1 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.14.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.13.6 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.13.5 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.13.3 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.13.2 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.13.1 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.13.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.12.0 lib/copy_tuner_client/prefixed_logger.rb
copy_tuner_client-0.11.0 lib/copy_tuner_client/prefixed_logger.rb