Sha256: fc881b3707e24892816b4d8e380e1708f4080f99742cd8197b459deee7278717

Contents?: true

Size: 1.31 KB

Versions: 9

Compression:

Stored size: 1.31 KB

Contents

require 'logger'

# This log overlay module, provides access to the +log+ method.
module RSpecSystem::Log
  class Logger
    attr_accessor :io

    def initialize(io)
      @io = io
    end

    def debug(text)
      io << bold(color('Debug: ', :blue)) << text << "\n"
    end

    def info(text)
      io << bold('Info: ') << text << "\n"
    end

    def warn(text)
      io << 'Warn: ' << text << "\n"
    end

    def fatal(text)
      io << 'Fatal: ' << text << "\n"
    end

    def unknown(text)
      io << 'Unknown: ' << text << "\n"
    end

    def error(text)
      io << 'Error: ' << text << "\n"
    end
  end

  # Return the default Logger object.
  #
  # @return [Logger] default logger object
  def log
    return @logger if @logger
    @logger = Logger.new(output)
    @logger
  end

  def formatter
    RSpec.configuration.formatters.each do |f|
      if f.is_a? RSpecSystem::Formatter then
        return f
      end
    end
  end

  class NullStream
     def <<(o); self; end
  end

  def output
    begin
      formatter.output
    rescue NameError
      NullStream.new
    end
  end

  def bold(text)
    begin
      formatter.send(:bold, text)
    rescue NameError
      ""
    end
  end

  def color(text, color)
    begin
      formatter.send(:color, text, color)
    rescue NameError
      ""
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rspec-system-2.8.0 lib/rspec-system/log.rb
rspec-system-2.7.2 lib/rspec-system/log.rb
rspec-system-2.7.1 lib/rspec-system/log.rb
rspec-system-2.7.0 lib/rspec-system/log.rb
rspec-system-2.6.0 lib/rspec-system/log.rb
rspec-system-2.5.1 lib/rspec-system/log.rb
rspec-system-2.5.0 lib/rspec-system/log.rb
rspec-system-2.4.0 lib/rspec-system/log.rb
rspec-system-2.3.0 lib/rspec-system/log.rb