1

我正在使用 ZF2 Zend 记录器来附加日志数据,如下所示:

$logger = new Logger;
$writer = new LogWriter($log_path);

用于在实现 LDAP 身份验证时附加日志消息。

但我收到如下错误消息:

File:
E:\xampp\htdocs\project\vendor\ZF2\library\Zend\Log\Writer\Stream.php:82


Message:
  "/tmp/ldap.log" cannot be opened with mode "a"

请帮我解决这个问题。

4

1 回答 1

2

你可以做这样的事情

   $logdir = "tmp/";
   // check if the log dir exists
   if (!file_exists($logdir)) {
       mkdir($logdir, 0777, true);
   }

   $stream = fopen($logdir . "ldap.log", 'a', false);
   $writer = new Stream($stream);
   $logger = new Logger();
   $logger->addWriter($writer);
   // add your message
   $message = "log appended to file at ".time();
   $logger->info($message)

还要确保文件具有正确的写权限

   chmod 777 /tmp/ldap.log
于 2013-08-02T07:33:46.270 回答