BEGIN {
# Extract relative path and basename from script name.
$me = $FindBin::Script;
-
+
# Remove .pl for Perl scripts that have that extension
$me =~ s/\.pl$//;
} # BEGIN
my $disposition = $parms{disposition} ? $parms{disposition} : 'perm';
my $timestamped = $parms{timestamped} ? $parms{timestamped} : 'FALSE';
my $append = $parms{append} ? '>>' : '>';
- my $extension = $parms{extension} ? $parms{extension} : 'log';
my $logfile;
- $name = "$name.$extension";
+ if (defined $parms{extension}) {
+ $name .= ".$parms{extension}" unless $parms{extension} eq '';
+ } else {
+ $name .= '.log';
+ } # if
open $logfile, $append, "$path/$name"
or error "Unable to open logfile $path/$name - $!", 1;
# Set unbuffered output
$logfile->autoflush ();
- set_verbose
- if $ENV{VERBOSE};
- set_debug
- if $ENV{DEBUG};
+ set_verbose if $ENV{VERBOSE};
+ set_debug if $ENV{DEBUG};
return bless {
path => $path,
} # while
close $file;
-
+
return;
} # append
sub name () {
my ($self) = @_;
-
+
=pod
=head3 name
sub fullname () {
my ($self) = @_;
-
+
=pod
=head3 fullname
=cut
$self->log ($msg, $nolinefeed);
-
+
verbose $msg, undef, $nolinefeed;
-
+
return;
} # msg
=cut
$self->log ($msg, $nolinefeed);
-
+
display $msg, undef, $nolinefeed;
-
+
return;
} # disp
=cut
$increment ||= 1;
-
+
$self->{errors} += $increment;
+
+ return;
} # incrementErr
sub err ($;$) {
my ($self, $msg, $errno) = @_;
-
+
=pod
=head3 err ($msg, $errno)
$msg = "ERROR: $msg";
} # if
- $self->log ($msg);
-
+ $self->msg($msg);
+
$self->incrementErr;
-
+
exit $errno if $errno;
-
+
return;
} # err
footing => $footing,
data => $logfile
);
-
+
close $logfile
or error "Unable to close logfile $log_filename", 1;
-
+
return;
} # maillog
$msg = "$me: " . YMDHM . ": $msg" if $self->{timestamped};
display $msg, $self->{handle}, $nolinefeed;
-
+
return;
} # log
display "\$ $cmd", $self->{handle} if get_debug;
- my $status = open my $output, '|', "$cmd 2>&1";
+ my $status = open my $output, '-|', "$cmd 2>&1";
if (!$status) {
$self->{error}++;
sub loglines () {
my ($self) = @_;
-
+
=pod
=head3 loglines
=cut
warning $msg, $warnno;
-
+
if ($warnno) {
$msg = "WARNING #$warnno: $msg";
} else {
$self->log ($msg);
$self->{warnings}++;
-
+
return;
} # warn
sub errors () {
my ($self) = @_;
-
+
=pod
=head3 errors ()
sub warnings () {
my ($self) = @_;
-
+
=pod
=head3 warnings ()
if ($self->{disposition} eq 'temp') {
if ($self->{errors} == 0 and
- $self->{warnings} == 0) {
+ $self->{warnings} == 0) {
unlink $self->fullname;
} # if
} # if
-
+
return;
} # destroy