This script is named o.rb:
@logger = Logger.new(STDOUT)
@logger.info "start_time : #{start_time}"
When I run it using ./o.rb, the output on the console 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 issue while using the simple puts function.
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 using ./foo.rb, it writes correctly to the console output.
When I run ./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 Ruby version is 1.8.7.
LogDevice::newcalls@dev.sync = true-- which asks for unbuffered operation.