requiresLayout = true; } public function __destruct() { $this->close(); } public function activateOptions() {} protected function open(){ if($this->fp) return; $fileName = $this->getFile(); if(trim($fileName) != ''){ 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) { @chown($fileName, 'apache'); @chgrp($fileName, 'apache'); @chmod($fileName, 0777); /*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; } } 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) $this->open(); 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 and opens the file where the log output will go. * * This is an overloaded method. It can be called with: * - setFile(string $fileName) to set filename. * - setFile(string $fileName, boolean $append) to set filename and append. * * TODO: remove overloading. Use only file as alias to filename */ public function setFile() { $numargs = func_num_args(); $args = func_get_args(); if($numargs == 1 and is_string($args[0])) { $this->setFileName($args[0]); } else if ($numargs >=2 and is_string($args[0]) and is_bool($args[1])) { $this->setFile($args[0]); $this->setAppend($args[1]); } } /** * @return string */ public function getFile() { return $this->getFileName(); } /** * @return boolean */ public function getAppend() { return $this->append; } public function setAppend($flag) { $this->append = LoggerOptionConverter::toBoolean($flag, true); } public function setFileName($fileName) { $this->fileName = $fileName; } /** * @return string */ public function getFileName() { return $this->fileName; } }