projects
/
dweather.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Send wind even if it hasn't changed
[dweather.git]
/
SMGLog.pm
diff --git
a/SMGLog.pm
b/SMGLog.pm
index ddff2502bb0ac066b12aa2e1811c95d401fe7621..9adf77a75a977d4d7cf01badb9e79aaa29f6fd23 100644
(file)
--- a/
SMGLog.pm
+++ b/
SMGLog.pm
@@
-53,6
+53,7
@@
sub new
my $dir = "$path/$prefix";
$ref->{prefix} = $dir;
$ref->{suffix} = $suffix || 'log';
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;
# make sure the directory exists
mkpath($dir, 0, 0777) unless -d $dir;
@@
-88,7
+89,7
@@
sub open
$self->{fn} = sprintf "$self->{prefix}/$year/%02d%02d", $month, $day;
$self->{fn} .= ".$self->{suffix}" if $self->{suffix};
$self->{fn} = sprintf "$self->{prefix}/$year/%02d%02d", $month, $day;
$self->{fn} .= ".$self->{suffix}" if $self->{suffix};
- $self->{mode} = $mode || '
r
';
+ $self->{mode} = $mode || '
a+
';
my $fh = new IO::File $self->{fn}, $mode, 0666;
return unless $fh;
my $fh = new IO::File $self->{fn}, $mode, 0666;
return unless $fh;
@@
-124,11
+125,11
@@
sub opennext
sub write
{
my ($self, $dayno, $line) = @_;
sub write
{
my ($self, $dayno, $line) = @_;
- if (
!$self->{fh} || $self->{mode} ne "r" || $dayno != $self->{dayno}
) {
- $self->open($dayno, "
>>
") or confess "can't open $self->{fn} $!";
- }
+ 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
}
# read a line from an opened file