Sha256: ad52503550f687bee7c42c3c8f7160eaaa961c909212481b675059623266a669

Contents?: true

Size: 675 Bytes

Versions: 3

Compression:

Stored size: 675 Bytes

Contents

module MockEM

  # Logs all messages with the specified prefix.
  # Warning: this is a not a full-fledged Logger implementation, it just logs string messages.
  class LoggerWithPrefix

    attr_reader :prefix
    attr_reader :raw_logger

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

    def debug(msg); log_with_prefix(:debug, msg)  end
    def info(msg);  log_with_prefix(:info,  msg)  end
    def warn(msg);  log_with_prefix(:warn,  msg)  end
    def error(msg); log_with_prefix(:error, msg)  end

    private

    def log_with_prefix(level, msg)
      @raw_logger.__send__(level, "#{prefix}: #{msg}")
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mock_em-0.2.1 lib/mock_em/logger_with_prefix.rb
mock_em-0.2.0 lib/mock_em/logger_with_prefix.rb
mock_em-0.1.0 lib/mock_em/logger_with_prefix.rb