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;
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