juo has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I wonder if anybody had any good suggestions to create a comphrehensive log file when running scripts. The log file should contain printed lines send to it but also contain all the warnings and errors from the STDOUT. Is their a good way to do this besides from re-directing my STDOUT in the beginning of a script direclty to a filehandle.
open STDOUT ">whatever.dat"; # Here comes all the coding close STDOUT;
I don't want to remove my STDOUT, I just want in parallel capture it in a log file.
The result could be something like this
PRINT INFO 12December2004 "Importing JOB x into database" PRINT WARNING 12December2004 "Job did already exist" STDOUT ERROR 12December2004 "No permission to overwrite job"
So instead of having all the time an open filehandle is their another way to just capture when something goes to the STDOUT and then write this into a file. For the print I think I can do this easily with the following subroutine but I don't have an idea to also re-direct STDOUT errors and warnings to that routine
sub WriteLog { my ($script,$type,$log) = @_; $logfile = $job_path.'/user/LogFile.txt'; open (LOG, "$logfile") || die "File does not exist\n"; print "$script\t$type\t$today\t$log\n"; close (LOG); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Creating a comprehensive log file
by redhotpenguin (Deacon) on Dec 16, 2004 at 03:55 UTC | |
Re: Creating a comprehensive log file
by NetWallah (Canon) on Dec 16, 2004 at 03:42 UTC | |
Re: Creating a comprehensive log file
by sauoq (Abbot) on Dec 16, 2004 at 03:47 UTC | |
by juo (Curate) on Dec 16, 2004 at 06:05 UTC | |
Re: Creating a comprehensive log file
by demerphq (Chancellor) on Dec 16, 2004 at 17:16 UTC |