Monday, May 28, 2012

Log Redirection in Ruby

If you wan to redirect your methods log to a file instead of console and after writing the log to the file the output should back to console then follow the below instructions.

def example()
 oldout=$stdout
 $stdout=File.new("",'a')
.
.
.                   
.
.
$stdout=oldout
end


you can change the type of writing to log file with replace of 'w', 'w+' etc.. depends on your requirements.

No comments:

Post a Comment