attempt to fix myalias/mycall external usurpation
[spider.git] / perl / DXLog.pm
index bdf441bb56c5ae16735bb896aa035bb5c0fb1091..a332d39208336c26c5c9c012bc4a3a7b6ac6959a 100644 (file)
@@ -20,7 +20,7 @@
 # 
 # Copyright (c) - 1998 Dirk Koopman G1TLH
 #
-# $Id$
+#
 #
 
 package DXLog;
@@ -38,7 +38,7 @@ use Carp;
 
 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 = {};
-       $ref->{prefix} = "$main::data/$prefix";
+       my $ref = bless {}, __PACKAGE__;
+       localdata_mv($prefix);
+       $ref->{prefix} = "$main::local_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;
+       
+       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";
@@ -98,6 +101,13 @@ sub open
        return $self->{fh};
 }
 
+sub fn
+{
+       my ($self, $jdate) = @_;
+       
+       return $self->_genfn($jdate);
+}
+
 sub delete($$)
 {
        my ($self, $jdate) = @_;
@@ -146,6 +156,7 @@ sub unixtoj($$)
 sub write($$$)
 {
        my ($self, $jdate, $line) = @_;
+       return unless $self && $jdate;
        if (!$self->{fh} || 
                $self->{mode} ne ">>" || 
                $jdate->year != $self->{jdate}->year || 
@@ -184,10 +195,18 @@ sub close
 sub DESTROY
 {
        my $self = shift;
+       delete $logs{$self};
        undef $self->{fh};                      # close the filehandle
        delete $self->{fh} if $self->{fh};
 }
 
+sub flushall
+{
+       foreach my $l (values %logs) {
+               $l->{fh}->flush if exists $l->{fh};
+       }
+}
+
 # log something in the system log 
 # this routine is exported to any module that declares DXLog
 # it takes all its args and joins them together with the unixtime writes them out as one line
@@ -200,8 +219,12 @@ sub Log
 
 sub LogDbg
 {
-       DXDebug::dbg($_) for @_;
-       Log(@_);
+       my $cat = shift;
+       foreach my $m (@_) {
+               DXDebug::dbgsetcat($cat);
+               DXDebug::dbg($m);
+               Log($cat, $m);
+       }
 }
 
 sub Logclose