remove any leading ::ffff: on ipv4 addresses
[spider.git] / perl / DXLog.pm
index bdf441bb56c5ae16735bb896aa035bb5c0fb1091..287b766e8bdf95ad72614e49b6d997939eebb8ff 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";
@@ -146,6 +149,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 +188,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 +212,9 @@ sub Log
 
 sub LogDbg
 {
+       my $cat = shift;
        DXDebug::dbg($_) for @_;
-       Log(@_);
+       Log($cat, @_);
 }
 
 sub Logclose