我正在使用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"
请帮我解决此问题。
答案 0 :(得分: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