module Brightbox
  module Logging
    def self.included(base)
      base.extend MixinMethods
      base.send(:include, MixinMethods)
    end

    module MixinMethods
      def error(s='')
        $stderr.write s
        $stderr.write "\n"
        $stderr.flush
      end

      def info(s='')
        STDERR.write s
        STDERR.write "\n"
        STDERR.flush
      end

      def warn(s='')
        info "WARN: #{s}"
      end

      def data(s)
        $stdout.write s
        $stdout.write "\n"
      end

      def debug(s)
        if ENV['DEBUG']
          STDERR.write "DEBUG: "
          STDERR.write s
          STDERR.write "\n"
        end
      end
    end
  end
  include Logging
end

module Brightbox
  module Logging
    def self.included(base)
      base.extend MixinMethods
      base.send(:include, MixinMethods)
    end

    module MixinMethods
      def error(s='')
        $stderr.write s
        $stderr.write "\n"
        $stderr.flush
      end

      def info(s='')
        $stderr.write s
        $stderr.write "\n"
        $stderr.flush
      end

      def warn(s='')
        info "WARN: #{s}"
      end

      def data(s)
        $stdout.write s
        $stdout.write "\n"
      end

      def debug(s)
        if ENV['DEBUG']
          $stderr.write "DEBUG: "
          $stderr.write s
          $stderr.write "\n"
        end
      end
    end
  end
  include Logging
end

Use globals rather than constants for IO
Use globals rather than constants for IO

Normally STDOUT == $stdout so they can be used interchangably. Trying to
test the captured output and it is inconsistent because we are logging
to either STDOUT or $stdout (or the err version).

This makes it impossible to capture ALL output and check since the IO is
a mixture.

We can't cleanly reset the constants so using the globals.
