This script has a name o.rb:
@logger = Logger.new(STDOUT)
@logger.info "start_time : #{start_time}"
When I run it with ./o.rb, the console output is correct.
However, when I tried ./o.rb > log.txt 2>&1, the log file is empty!
Why did this happen?
I have the same problem when using a simple function puts.
UPDATE
This will reproduce this issue:
require 'logger'
logger = Logger.new(STDOUT)
loop do
logger.info "This is a test haha"
sleep(1)
end
When I run it with ./foo.rb, it correctly writes the console output.
When I start ./foo.rb > log.txt, I get nothing.
Also, when I use ./foo.rb | tee log.txt, nothing is written to the console and the log file is empty.
The log.txt file was created, but remains empty.
My version of Ruby is 1.8.7.