From: Erik Veenstra Date: 2007-03-28T01:39:55+09:00 Subject: Re: How do I implement the Unix 'tee' function for $stdout? > I already discovered that I can redirect $stdout just by > pointing it at a new file handle. But what I really want is > to have the output continue to STDOUT but ALSO go into my > logging file along with a pile of trace data. This is very > similar to the Unix program 'tee' Here's the code of my own log library that does exactly what you want. gegroet, Erik V. - http://www.erikveen.dds.nl/ ---------------------------------------------------------------- ["$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("logfile.log", "a") do |f| f.puts [std[1..-1].upcase, caller[2], text].join(" ") end end old_write.call(text) end end end $stdout.puts "text on stdout" $stderr.puts "text on stderr" ----------------------------------------------------------------