close(); } public function activateOptions() { $fileName = $this->getFile(); if(!is_file($fileName)) { $dir = dirname($fileName); if(!is_dir($dir)) { mkdir($dir, 0777, true); } } $this->fp = fopen($fileName, ($this->getAppend()? 'a':'w')); if($this->fp) { if(flock($this->fp, LOCK_EX)) { if($this->getAppend()) { fseek($this->fp, 0, SEEK_END); } fwrite($this->fp, $this->layout->getHeader()); flock($this->fp, LOCK_UN); $this->closed = false; } else { // TODO: should we take some action in this case? $this->closed = true; } } else { $this->closed = true; } } public function close() { if($this->closed != true) { if($this->fp and $this->layout !== null) { if(flock($this->fp, LOCK_EX)) { fwrite($this->fp, $this->layout->getFooter()); flock($this->fp, LOCK_UN); } fclose($this->fp); } $this->closed = true; } } public function append(LoggerLoggingEvent $event) { if($this->fp and $this->layout !== null) { if(flock($this->fp, LOCK_EX)) { fwrite($this->fp, $this->layout->format($event)); flock($this->fp, LOCK_UN); } else { $this->closed = true; } } } /** * Sets the file where the log output will go. * @param string $file */ public function setFile($file) { $this->file = $file; } /** * @return string */ public function getFile() { return $this->file; } /** * @return boolean */ public function getAppend() { return $this->append; } public function setAppend($flag) { $this->append = LoggerOptionConverter::toBoolean($flag, true); } /** * Sets the file where the log output will go. * @param string $fileName * @deprecated Use setFile() instead. */ public function setFileName($fileName) { $this->setFile($fileName); } /** * @return string * @deprecated Use getFile() instead. */ public function getFileName() { return $this->getFile(); } }