Sha256: 8a94cb3c946d81d620751b99e0d3aebac69b5530f8e15b99cb36d75d0ff24274

Contents?: true

Size: 678 Bytes

Versions: 5

Compression:

Stored size: 678 Bytes

Contents

module Spacebunny
  # Log on multiple outputs at the same time
  #
  # Usage example:
  #
  # log_file = File.open("log/debug.log", "a")
  # Logger.new Spacebunny::Logger.new(STDOUT, log_file)

  class Logger
    def initialize(*args)
      @streams = []
      args.each do |a|
        case a
          when String
            # This is a file path
            puts File.open(a, 'a+').inspect
            @streams << File.open(a, 'a+')
          else
            @streams << a
        end
      end
    end

    def write(*args)
      @streams.each do |lo|
        lo.write(*args)
        lo.flush
      end
    end

    def close
      @streams.each(&:close)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spacebunny-1.2.0 lib/spacebunny/logger.rb
spacebunny-1.1.2 lib/spacebunny/logger.rb
spacebunny-1.1.1 lib/spacebunny/logger.rb
spacebunny-1.1.0 lib/spacebunny/logger.rb
spacebunny-1.0.0 lib/spacebunny/logger.rb