fix swearing logging so that it is better.
[spider.git] / perl / DXLog.pm
index 748df39c782990d8216583f4c39782e1da3d6beb..785483533c562f50dfc438e30ecfebfda9cf024b 100644 (file)
@@ -27,7 +27,7 @@ package DXLog;
 
 require Exporter;
 @ISA = qw(Exporter);
-@EXPORT = qw(Log Logclose);
+@EXPORT = qw(Log LogDbg Logclose);
 
 use IO::File;
 use DXVars;
@@ -37,6 +37,13 @@ use Julian;
 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);
 
 $log = new('log', 'dat', 'm');
@@ -85,15 +92,14 @@ sub open
        
        $mode = 'r' if !$mode;
        $self->{mode} = $mode;
+       $self->{jdate} = $jdate;
        
        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
        $self->{fh} = $fh;
 
-       $self->{jdate} = $jdate;
-       
-#      DXDebug::dbg("opening $self->{fn}\n") if isdbg("dxlog");
+#      print "opening $self->{fn}\n";
        
        return $self->{fh};
 }
@@ -149,7 +155,7 @@ sub write($$$)
        if (!$self->{fh} || 
                $self->{mode} ne ">>" || 
                $jdate->year != $self->{jdate}->year || 
-               $jdate->thing != $self->{jdate}->year) {
+               $jdate->thing != $self->{jdate}->thing) {
                $self->open($jdate, ">>") or confess "can't open $self->{fn} $!";
        }
 
@@ -198,6 +204,12 @@ sub Log
        $log->writeunix($t, join('^', $t, @_) );
 }
 
+sub LogDbg
+{
+       DXDebug::dbg($_[$#_]);
+       Log(@_);
+}
+
 sub Logclose
 {
        $log->close();