X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXLog.pm;h=db7dffdd430a0977e306fa83d0afcff4ee671e95;hb=770092d94f96b6d22a38fb33e0056b4779a8a1ab;hp=07038433d440a3161dc6aa4c597ceefd9ea60c41;hpb=b953903f1c33ae35ce24bad344e46ab17b0b5d95;p=spider.git diff --git a/perl/DXLog.pm b/perl/DXLog.pm index 07038433..db7dffdd 100644 --- a/perl/DXLog.pm +++ b/perl/DXLog.pm @@ -20,7 +20,7 @@ # # Copyright (c) - 1998 Dirk Koopman G1TLH # -# $Id$ +# # package DXLog; @@ -34,17 +34,11 @@ use DXVars; use DXUtil; use Julian; -use Carp; +use Carp qw(confess cluck); use strict; -use vars qw($VERSION $BRANCH); -$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); -$main::build += $VERSION; -$main::branch += $BRANCH; - -use vars qw($log); +use vars qw($log %logs); $log = new('log', 'dat', 'm'); @@ -54,14 +48,17 @@ $log = new('log', 'dat', 'm'); sub new { my ($prefix, $suffix, $sort) = @_; - my $ref = {}; + my $ref = bless {}, __PACKAGE__; $ref->{prefix} = "$main::data/$prefix"; $ref->{suffix} = $suffix if $suffix; $ref->{sort} = $sort; # make sure the directory exists mkdir($ref->{prefix}, 0777) unless -e $ref->{prefix}; - return bless $ref; + $logs{$ref} = $ref; + $ref->{jdate} = $ref->unixtoj($main::systime); + + return $ref; } sub _genfn @@ -96,7 +93,7 @@ sub open my $fh = new IO::File $self->{fn}, $mode, 0666; return undef if !$fh; - $fh->autoflush(1) if $mode ne 'r'; # make it autoflushing if writable + $fh->autoflush(0); # autofluahing off $self->{fh} = $fh; # print "opening $self->{fn}\n"; @@ -152,10 +149,14 @@ sub unixtoj($$) sub write($$$) { my ($self, $jdate, $line) = @_; + cluck("Log::write \$jdate undefined") unless $jdate; +# cluck("Log::write \$self->jdate undefined") unless $self->{jdate}; if (!$self->{fh} || - $self->{mode} ne ">>" || - $jdate->year != $self->{jdate}->year || - $jdate->thing != $self->{jdate}->thing) { + $self->{mode} ne ">>" || + $jdate->year != + $self->{jdate}->year || + $jdate->thing + != $self->{jdate}->thing) { $self->open($jdate, ">>") or confess "can't open $self->{fn} $!"; } @@ -187,11 +188,11 @@ sub close delete $self->{fh}; } -sub DESTROY +sub flushall { - my $self = shift; - undef $self->{fh}; # close the filehandle - delete $self->{fh} if $self->{fh}; + foreach my $l (values %logs) { + $l->{fh}->flush if exists $l->{fh}; + } } # log something in the system log @@ -200,7 +201,7 @@ sub DESTROY # The user is responsible for making sense of this! sub Log { - my $t = time; + my $t = $main::systime; $log->writeunix($t, join('^', $t, @_) ); }