Subject: | Log::Log4perl::Appender::File dies when writing undef |
Basically, it boils down to the line that calls syswrite:
syswrite $fh, $params{message} or
die "Cannot syswrite to '$self->{filename}': $!";
This is not quite right. If the message has zero bytes to it, it will die, and
$! will not be set. According to the perldoc, the correct way to do this
would be:
defined (syswrite $fh, $params{message}) or
die "Cannot syswrite to '$self->{filename}': $!";
(parens may not be required) That is, syswrite returns undef on failure, a
return of 0 merely means that syswrite wrote nothing. Another alternative
would be to compare the return of syswrite to the length of the message to
ensure they're the same, but that, too, gets tricky (not impossibly) in the
case of undef.