Re: Logging STDERR and other output
- From: a.r.ferreira@xxxxxxxxx (Adriano Ferreira)
- Date: Thu, 30 Aug 2007 10:59:13 -0300
On 8/30/07, Beginner <dermot@xxxxxxxxxxxxxxxx> wrote:
On 30 Aug 2007 at 6:32, Peter Scott wrote:
On Thu, 30 Aug 2007 10:32:01 +0100, Beginner wrote:
I want all the output plus any error messages to got to a log file. I
used the BEGIN block to direct STDERR into the file:
BEGIN {
open(STDERR, ">>/usr/local/myreports/report.log") || die "Can't
write to file: $!\n";
}
use strict;
use warnings;
...
### Start some logging ###
my $log;
my $logfile = "$dist_dir/report.log";
open($log,">>$logfile") || die "Can't write to $logfile: $!\n";
print $log "$0 called at ", &tm," with pid $$\n";
Why are you using a BEGIN block? Why not just make it the first
executable statement? Do you have any other 'use' statements in the
program?
Yes I do. Several standard modules plus one or 2 of my own. The BEGIN
block adds the path to my modules as well so it really looks like
this at the moment (I have tested Mumia's INIT yet):
BEGIN { unshift @INC, '/etc/perl';
This is better done with
use lib qw(/etc/perl);
which doesn't need the surrounding "BEGIN" block.
$| = 1;
open(STDERR, ">>/usr/local/myreports/report.log") || die
"Can't write to file: $!\n";
}
use MY::MakePDF;
use MY::SendEmail;
use MY::Number;
use MY::PDF_Handler;
use File::Basename;
use strict;
use warnings;
I want the STDERR from those modules to go to the log file also.
Just perfect ;-)
.
- Follow-Ups:
- Re: Logging STDERR and other output
- From: Beginner
- Re: Logging STDERR and other output
- References:
- Logging STDERR and other output
- From: Beginner
- Re: Logging STDERR and other output
- From: Peter Scott
- Re: Logging STDERR and other output
- From: Beginner
- Logging STDERR and other output
- Prev by Date: Re: Logging STDERR and other output
- Next by Date: parsing HTML content
- Previous by thread: Re: Logging STDERR and other output
- Next by thread: Re: Logging STDERR and other output
- Index(es):
Relevant Pages
|
|