----- Original Message -----
From: Kevin Meltzer <[EMAIL PROTECTED]>
To: Peter Lemus <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, April 26, 2001 10:07 PM
Subject: Re: How to create a log file from a perl script
> Hi Peter,
>
> Look at the perlopentut man page:
>
> perldoc perlopentut
>
> That will show you how to open a file(s). Then, you can just write to
them. If
> I want all my 'print' statements in a script to print to a specific file,
I
> generally do something like:
>
> sub DEBUG () { 1 }; # Or some level of debugness
>
> open(LOG, ">>$log") or die "Can't open $log: $!";
> select(LOG);
>
> print "I will go to $log" if DEBUG;
> print "I may go to the log" if DEBUG > 1;
> etc...
>
> close LOG;
>
> But, YMMV. Someone else may have other tricks they use for logging.
>
>
Like:
use Carp;
use Carp qw(cluck);
open (OLD_STDERR, ">&STDERR")|| die 'can\'t store old STDERR: $!';
END{
close(OLD_STDERR); # to avoid global warning about constant OLD_STDERR used
only once
}
sub set_logfile{
if (!$_[0]) {open(STDERR, ">&OLD_STDERR")|| die "Can\'t reopen stderr:
$!";}
else {open(STDERR,">>$_[0]")|| croak "Can't open logfile: $_[0]: $!" ;}
}
sub log{
my $message="\nLOG\t".scalar(localtime)."\:\n".$_[0];
local $Carp::CarpLevel = 1;
carp($message);
}