projects
/
clearscm.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rsync Mikey & Kent
[clearscm.git]
/
lib
/
Logger.pm
diff --git
a/lib/Logger.pm
b/lib/Logger.pm
index
4d31d3e
..
084fbcb
100644
(file)
--- a/
lib/Logger.pm
+++ b/
lib/Logger.pm
@@
-83,17
+83,17
@@
use Utils;
my ($error_color, $warning_color, $command_color, $highlight_color, $normal) = "";
my ($error_color, $warning_color, $command_color, $highlight_color, $normal) = "";
-
my
$me;
+
our
$me;
BEGIN {
# Extract relative path and basename from script name.
$me = $FindBin::Script;
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
# Remove .pl for Perl scripts that have that extension
$me =~ s/\.pl$//;
} # BEGIN
-sub new
(;%)
{
+sub new
(;%)
{
my ($class, %parms) = @_;
=pod
my ($class, %parms) = @_;
=pod
@@
-164,21
+164,22
@@
Returns:
my $disposition = $parms{disposition} ? $parms{disposition} : 'perm';
my $timestamped = $parms{timestamped} ? $parms{timestamped} : 'FALSE';
my $append = $parms{append} ? '>>' : '>';
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;
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
open $logfile, $append, "$path/$name"
or error "Unable to open logfile $path/$name - $!", 1;
# Set unbuffered output
- $logfile->autoflush
();
+ $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,
return bless {
path => $path,
@@
-191,7
+192,7
@@
Returns:
}, $class; # bless
} # new
}, $class; # bless
} # new
-sub append
($) {
+sub append($) {
my ($self, $filename) = @_;
=pod
my ($self, $filename) = @_;
=pod
@@
-236,13
+237,13
@@
Returns:
} # while
close $file;
} # while
close $file;
-
+
return;
} # append
return;
} # append
-sub name
() {
+sub name() {
my ($self) = @_;
my ($self) = @_;
-
+
=pod
=head3 name
=pod
=head3 name
@@
-278,9
+279,9
@@
Returns:
return $self->{name};
} # name
return $self->{name};
} # name
-sub fullname
() {
+sub fullname() {
my ($self) = @_;
my ($self) = @_;
-
+
=pod
=head3 fullname
=pod
=head3 fullname
@@
-316,7
+317,7
@@
Returns:
return "$self->{path}/$self->{name}";
} # fullname
return "$self->{path}/$self->{name}";
} # fullname
-sub msg
($;$) {
+sub msg($;$) {
my ($self, $msg, $nolinefeed) = @_;
=pod
my ($self, $msg, $nolinefeed) = @_;
=pod
@@
-359,13
+360,13
@@
Returns:
=cut
$self->log ($msg, $nolinefeed);
=cut
$self->log ($msg, $nolinefeed);
-
+
verbose $msg, undef, $nolinefeed;
verbose $msg, undef, $nolinefeed;
-
+
return;
} # msg
return;
} # msg
-sub disp
($;$) {
+sub disp($;$) {
my ($self, $msg, $nolinefeed) = @_;
=pod
my ($self, $msg, $nolinefeed) = @_;
=pod
@@
-408,13
+409,13
@@
Returns:
=cut
$self->log ($msg, $nolinefeed);
=cut
$self->log ($msg, $nolinefeed);
-
+
display $msg, undef, $nolinefeed;
display $msg, undef, $nolinefeed;
-
+
return;
} # disp
return;
} # disp
-sub incrementErr
(;$) {
+sub incrementErr(;$) {
my ($self, $increment) = @_;
=pod
my ($self, $increment) = @_;
=pod
@@
-452,13
+453,15
@@
Returns:
=cut
$increment ||= 1;
=cut
$increment ||= 1;
-
+
$self->{errors} += $increment;
$self->{errors} += $increment;
+
+ return;
} # incrementErr
} # incrementErr
-sub err
($;$) {
+sub err($;$) {
my ($self, $msg, $errno) = @_;
my ($self, $msg, $errno) = @_;
-
+
=pod
=head3 err ($msg, $errno)
=pod
=head3 err ($msg, $errno)
@@
-510,16
+513,16
@@
Returns:
$msg = "ERROR: $msg";
} # if
$msg = "ERROR: $msg";
} # if
- $self->
log
($msg);
-
+ $self->
msg
($msg);
+
$self->incrementErr;
$self->incrementErr;
-
+
exit $errno if $errno;
exit $errno if $errno;
-
+
return;
} # err
return;
} # err
-sub maillog
(%) {
+sub maillog(%) {
my ($self, %parms) = @_;
=pod
my ($self, %parms) = @_;
=pod
@@
-565,8
+568,7
@@
Returns:
my $footing = $parms{footing};
my $mode = $parms{mode};
my $footing = $parms{footing};
my $mode = $parms{mode};
- $mode = "plain"
- unless $mode;
+ $mode = "plain" unless $mode;
my $log_filename = "$self->{path}/$self->{name}";
my $log_filename = "$self->{path}/$self->{name}";
@@
-581,7
+583,7
@@
Returns:
. $footing;
} # if
. $footing;
} # if
- mail
(
+ mail(
from => $from,
to => $to,
cc => $cc,
from => $from,
to => $to,
cc => $cc,
@@
-591,14
+593,14
@@
Returns:
footing => $footing,
data => $logfile
);
footing => $footing,
data => $logfile
);
-
+
close $logfile
or error "Unable to close logfile $log_filename", 1;
close $logfile
or error "Unable to close logfile $log_filename", 1;
-
+
return;
} # maillog
return;
} # maillog
-sub log {
+sub log
($;$)
{
my ($self, $msg, $nolinefeed) = @_;
=pod
my ($self, $msg, $nolinefeed) = @_;
=pod
@@
-644,11
+646,11
@@
Returns:
$msg = "$me: " . YMDHM . ": $msg" if $self->{timestamped};
display $msg, $self->{handle}, $nolinefeed;
$msg = "$me: " . YMDHM . ": $msg" if $self->{timestamped};
display $msg, $self->{handle}, $nolinefeed;
-
+
return;
} # log
return;
} # log
-sub logcmd
($) {
+sub logcmd($) {
my ($self, $cmd) = @_;
=pod
my ($self, $cmd) = @_;
=pod
@@
-685,7
+687,7
@@
Returns:
display "\$ $cmd", $self->{handle} if get_debug;
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}++;
if (!$status) {
$self->{error}++;
@@
-707,9
+709,9
@@
Returns:
return ($?, @output);
} # logcmd
return ($?, @output);
} # logcmd
-sub loglines
() {
+sub loglines() {
my ($self) = @_;
my ($self) = @_;
-
+
=pod
=head3 loglines
=pod
=head3 loglines
@@
-745,7
+747,7
@@
Returns:
return ReadFile "$self->{path}/$self->{name}";
} # loglines
return ReadFile "$self->{path}/$self->{name}";
} # loglines
-sub warn
($;$) {
+sub warn($;$) {
my ($self, $msg, $warnno) = @_;
=pod
my ($self, $msg, $warnno) = @_;
=pod
@@
-789,7
+791,7
@@
Returns:
=cut
warning $msg, $warnno;
=cut
warning $msg, $warnno;
-
+
if ($warnno) {
$msg = "WARNING #$warnno: $msg";
} else {
if ($warnno) {
$msg = "WARNING #$warnno: $msg";
} else {
@@
-798,13
+800,13
@@
Returns:
$self->log ($msg);
$self->{warnings}++;
$self->log ($msg);
$self->{warnings}++;
-
+
return;
} # warn
return;
} # warn
-sub errors
() {
+sub errors() {
my ($self) = @_;
my ($self) = @_;
-
+
=pod
=head3 errors ()
=pod
=head3 errors ()
@@
-840,9
+842,17
@@
Returns:
return $self->{errors};
} # errors
return $self->{errors};
} # errors
-sub warnings () {
+sub dbug($) {
+ my ($self, $msg) = @_;
+
+ $self->log("DEBUG: $msg") if get_debug;
+
+ return;
+} # dbug
+
+sub warnings() {
my ($self) = @_;
my ($self) = @_;
-
+
=pod
=head3 warnings ()
=pod
=head3 warnings ()
@@
-878,18
+888,18
@@
Returns:
return $self->{warnings};
} # warnings
return $self->{warnings};
} # warnings
-sub DESTROY
() {
+sub DESTROY() {
my ($self) = @_;
close ($self->{handle});
if ($self->{disposition} eq 'temp') {
if ($self->{errors} == 0 and
my ($self) = @_;
close ($self->{handle});
if ($self->{disposition} eq 'temp') {
if ($self->{errors} == 0 and
-
$self->{warnings} == 0) {
+ $self->{warnings} == 0) {
unlink $self->fullname;
} # if
} # if
unlink $self->fullname;
} # if
} # if
-
+
return;
} # destroy
return;
} # destroy