I'm attempting to send emails at specific times of the day using MIME::Lite and the Windows Task Scheduler. Now, most of the time, when the script is run, no one will be near the machine, so I decided to send all errors to a log file.
Here's some sample code:
[red]
#Open Log file
open ( LOG, ">$log_out" );
#Attach message
eval {
$msg->attach( Type => 'AUTO', Path => $_ );
};
#If errors, call logger
logger ( "Image-attach error: $@\n", 1) if $@;
[/red]
If there are errors, I was hoping that the 'logger' function would be called, as follows:
[red]
sub logger {
my ($message, $quit) = @_;
my ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$isdst) = localtime( time() );
$mon++; #Starts at 0
$yr += 1900; #Add 1900 to start
print LOG "[$hour:$min $mday/$mon/$yr] $message\n";
if ( $quit ){
close (LOG);
exit;
}
}
[/red]
Unfortunately, when an error occurs, such as the msg->attach method failing, the error still displays on stdout and never in the log.
Does anyone know how I could fix this small problem?
Thanks in advance,
James.
Here's some sample code:
[red]
#Open Log file
open ( LOG, ">$log_out" );
#Attach message
eval {
$msg->attach( Type => 'AUTO', Path => $_ );
};
#If errors, call logger
logger ( "Image-attach error: $@\n", 1) if $@;
[/red]
If there are errors, I was hoping that the 'logger' function would be called, as follows:
[red]
sub logger {
my ($message, $quit) = @_;
my ($sec,$min,$hour,$mday,$mon,$yr,$wday,$yday,$isdst) = localtime( time() );
$mon++; #Starts at 0
$yr += 1900; #Add 1900 to start
print LOG "[$hour:$min $mday/$mon/$yr] $message\n";
if ( $quit ){
close (LOG);
exit;
}
}
[/red]
Unfortunately, when an error occurs, such as the msg->attach method failing, the error still displays on stdout and never in the log.
Does anyone know how I could fix this small problem?
Thanks in advance,
James.