X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=SMGLog.pm;h=9adf77a75a977d4d7cf01badb9e79aaa29f6fd23;hb=b4db08ed5cfe84618f1820fdc49b716ccaca61ec;hp=d52d9b3f57ec65e244a64d66cb15a4891fe585fe;hpb=94bc0e65b4da21f0d982ea9185f4a6f3651f78e4;p=dweather.git diff --git a/SMGLog.pm b/SMGLog.pm index d52d9b3..9adf77a 100644 --- a/SMGLog.pm +++ b/SMGLog.pm @@ -53,6 +53,7 @@ sub new my $dir = "$path/$prefix"; $ref->{prefix} = $dir; $ref->{suffix} = $suffix || 'log'; + $ref->{dayno} = int (time / 86400); # make sure the directory exists mkpath($dir, 0, 0777) unless -d $dir; @@ -124,11 +125,11 @@ sub opennext sub write { my ($self, $dayno, $line) = @_; - if (!$self->{fh} || $self->{mode} ne "r" || $dayno != $self->{dayno}) { + if ((!$self->{fh} || $dayno != $self->{dayno}) && $self->{mode} ne "r") { $self->open($dayno, "a+") or confess "can't open $self->{fn} $!"; - } + } - return $self->{fh}->print("$line\n"); + return $self->{fh} ? $self->{fh}->print("$line\n") : undef; } # read a line from an opened file