X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXLog.pm;h=db7dffdd430a0977e306fa83d0afcff4ee671e95;hb=770092d94f96b6d22a38fb33e0056b4779a8a1ab;hp=bdf441bb56c5ae16735bb896aa035bb5c0fb1091;hpb=776d7bb9277c9d24708e297f240395b51b0aaa93;p=spider.git diff --git a/perl/DXLog.pm b/perl/DXLog.pm index bdf441bb..db7dffdd 100644 --- a/perl/DXLog.pm +++ b/perl/DXLog.pm @@ -20,7 +20,7 @@ # # Copyright (c) - 1998 Dirk Koopman G1TLH # -# $Id$ +# # package DXLog; @@ -34,11 +34,11 @@ use DXVars; use DXUtil; use Julian; -use Carp; +use Carp qw(confess cluck); use strict; -use vars qw($log); +use vars qw($log %logs); $log = new('log', 'dat', 'm'); @@ -48,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 @@ -90,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"; @@ -146,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} $!"; } @@ -181,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 @@ -194,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, @_) ); }