stream = $streamOrUrl; } else { ErrorHandler::start(); if (isset($filePermissions) && ! file_exists($streamOrUrl) && is_writable(dirname($streamOrUrl))) { touch($streamOrUrl); chmod($streamOrUrl, $filePermissions); } $this->stream = fopen($streamOrUrl, $mode, false); $error = ErrorHandler::stop(); if (! $this->stream) { throw new Exception\RuntimeException(sprintf( '"%s" cannot be opened with mode "%s"', $streamOrUrl, $mode ), 0, $error); } } if (null !== $logSeparator) { $this->setLogSeparator($logSeparator); } if ($this->formatter === null) { $this->formatter = new SimpleFormatter(); } } /** * Write a message to the log. * * @param array $event event data * @return void * @throws Exception\RuntimeException */ protected function doWrite(array $event) { $line = $this->formatter->format($event) . $this->logSeparator; fwrite($this->stream, $line); } /** * Set log separator string * * @param string $logSeparator * @return Stream */ public function setLogSeparator($logSeparator) { $this->logSeparator = (string) $logSeparator; return $this; } /** * Get log separator string * * @return string */ public function getLogSeparator() { return $this->logSeparator; } /** * Close the stream resource. * * @return void */ public function shutdown() { if (is_resource($this->stream)) { fclose($this->stream); } } }