我在Perl拥有一台TCP服务器(Revision 5.0 edition 8 subversion 0),该服务器利用这一代号在档案中登录。
sub logger {
return if ($LOGFILE eq "") ;
my ($idt, $str) = @_ ;
unless( defined($str) ) {
$str = $idt ;
$idt = ;
}
my ($s,$m,$h,$J,$M,$A) = localtime(time()) ;
if(!open(OUT,">>$LOGFILE")) {
warn "logger:error open [$LOGFILE]:[$!]
";
return;
}
if (!printf OUT "%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d %s %s -> %s
",
$A+1900, $M+1, $J, $h, $m, $s, $idt, $HOSTNAME, $str) {
warn "logger:error print [$LOGFILE]:[$!]
";
return;
}
if (!close(OUT)) {
warn "logger:error close [$LOGFILE]:[$!]
";
return;
}
}
So there is simultaneous writing in this log file. Exceptionally , I have this error in STDERR:
printf() on closed filehandle logger :error print [/my/path/logFile.LOG]:[Bad File Descriptor]
without!
How can I resolve this problem?