X-Git-Url: http://scm.dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=perl%2FDXLog.pm;h=e8d289b0995079b531eb0ce8ff1431626583db3a;hb=9d24fd4aa2eb1bb4e9d86ada66e46f77962a5fa7;hp=07038433d440a3161dc6aa4c597ceefd9ea60c41;hpb=b953903f1c33ae35ce24bad344e46ab17b0b5d95;p=spider.git diff --git a/perl/DXLog.pm b/perl/DXLog.pm index 07038433..e8d289b0 100644 --- a/perl/DXLog.pm +++ b/perl/DXLog.pm @@ -20,7 +20,7 @@ # # Copyright (c) - 1998 Dirk Koopman G1TLH # -# $Id$ +# # package DXLog; @@ -38,14 +38,10 @@ use Carp; 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); +our %logobj; + $log = new('log', 'dat', 'm'); # create a log object that contains all the useful info needed @@ -61,7 +57,9 @@ sub new # make sure the directory exists mkdir($ref->{prefix}, 0777) unless -e $ref->{prefix}; - return bless $ref; + my $self = bless $ref; + $logobj{$self} = $self; + return $self; } sub _genfn @@ -96,7 +94,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) if $mode ne 'r'; # make it (not) autoflushing if writable $self->{fh} = $fh; # print "opening $self->{fn}\n"; @@ -187,9 +185,17 @@ sub close delete $self->{fh}; } +sub flush_all +{ + foreach my $l (values %logobj) { + $l->{fh}->flush if exists $l->{fh}; + } +} + sub DESTROY { my $self = shift; + delete $logobj{$self}; undef $self->{fh}; # close the filehandle delete $self->{fh} if $self->{fh}; }