Hello,
the following code solves my problem for now, but is there a "nicer"
solution?
--------------------- SOS --------------------
$logfile = File.new ‘log.txt’,'w’
def puts (*args) $defout.puts args; $logfile.puts args end
def putc (arg) $defout.putc arg; $logfile.putc arg end
def print(*args) $defout.print args; $logfile.print args end
def printf (format,a1=nil,a2=nil,a3=nil,a4=nil,a5=nil,a6=nil,a7=nil,a8
=nil)
$defout.printf format, a1,a2,a3,a4,a5,a6,a7,a8
$logfile.printf format, a1,a2,a3,a4,a5,a6,a7,a8
end
puts Time.new,1,2,3,4; printf "%02x ",127; print 1,2,3; putc ‘a’
-------------------- EOS ------------------------
Hello,
the following code solves my problem for now, but is there a “nicer”
solution?
--------------------- SOS --------------------
$logfile = File.new ‘log.txt’,‘w’
def puts (*args) $defout.puts args; $logfile.puts args end
def putc (arg) $defout.putc arg; $logfile.putc arg end
def print(*args) $defout.print args; $logfile.print args end
def printf (format,a1=nil,a2=nil,a3=nil,a4=nil,a5=nil,a6=nil,a7=nil,a8
=nil)
$defout.printf format, a1,a2,a3,a4,a5,a6,a7,a8
$logfile.printf format, a1,a2,a3,a4,a5,a6,a7,a8
end
puts Time.new,1,2,3,4; printf "%02x ",127; print 1,2,3; putc ‘a’
-------------------- EOS ------------------------
Under 1.6.8, overriding of ‘putc’ does not work properly. Example:
print “Hello”
putc 32
printf “world%s\n”, “!”
prints “Helloworld!\n” to STDOUT, but puts the correct answer in the log
file. But it works if you change it to:
$defout.putc 32
Any idea what is going on?
I’d forgot about 1.6.
class << (log = File.new(‘log.txt’,‘w’))
def write(s)
STDOUT.write(s)
super
end
end
$defout = log #if RUBY_VERSION < “1.7” ### same as builtin in 1.8, but slower
def putc(c)
$defout.write(c)
end #end
···
At Thu, 27 Feb 2003 23:03:43 +0900, Brian Candler wrote: