Question: I've got some code that I cobbled together from hints found that worked. But something is going wrong, and I am baffled. Nothing is sent to the screen, and file is empty.

Here's the program:

```
#!/usr/bin/env ruby -w

require "stringio"

class Tee

    def initialize
      date_str = `date '+%Y%m%d_%H%M%S'`.chomp
      @log = File.new("tee_output_example_#{date_str}.log","w")
    end

["$stdout", "$stderr"].each do |std|
   io           = eval(std)
   old_write    = io.method(:write)

   class << io
     self
   end.module_eval do
     define_method(:write) do |text|
       unless text =~ /^[\r\n]+$/       # Because puts calls twice.
         File.open(@log, "a") do |f|
#           f.puts [std[1..-1].upcase, caller[2], text].join(" ")
            f.puts text
         end
       end

       old_write.call(text)
     end
   end
 end
end

logger = Tee.new()

 logger.puts "text on stdout"
 logger.puts "Something else"

 $stdout = STDOUT
 $stderr = STDERR
 $stdout.puts "plain puts to $stdout"
 $stderr.puts "plain puts to $stderr"

```

Answer: 
I managed to solve it simply with this command:

```
STDOUT.reopen IO.popen "tee stdout.log", "a"
STDERR.reopen IO.popen "tee stderr.log", "a"

```
Your expectations aren't very clear to me, but this seems to be a reasonable start (with several directions you could take it depending on your ultimate goal).

```
#!/usr/bin/env ruby -w

class Tee
  attr_accessor :log_file

  def initialize()
    self.log_file = File.open "tee_output_example_#{date_str}.log", "w"
    at_exit { log_file.close }
  end

  def date_str
    Time.now.strftime "%Y%m%d_%H%M%S"
  end

  def puts(*strings)
    log_file.puts(*strings)
    $stdout.puts(*strings)
  end
end

# will be sent to both $stdout and the logfile
logger = Tee.new
logger.puts "text on stdout"
logger.puts "Something else"

# will only be sent to $stdout or $stderr
$stdout.puts "plain puts to $stdout"
$stderr.puts "plain puts to $stderr"

```