For a while now, we have been testing a script that runs several cluster applications. We found the error output went only to the screen of shell where it was run. making it difficult for multiple to work together to locate the problem.
Directing STDERR to a file helped, but it was hard to figure out where in the script the error occurred. I found this code works best by redirecting STDOUT and STDERR both to the log file. It seems to work well, but we've only started using it. Do you see any problems or ways to improve this?
use strict;
# Set up main log
open LOG, ">$logfile" || die "$0: Can't open log file!";
open ( STDERR, ">>$logfile" );
open ( STDOUT, ">>$logfile" );
select( LOG );
$| = 1; # Turn on buffer autoflush for log output
select( STDOUT );