コード例 #1
0
 public function testFlush()
 {
     $this->outStream->write("Some data");
     $this->outStream->flush();
     $this->outStream->close();
     try {
         $this->outStream->flush();
         $this->fail("Expected IOException when attempting to flush a closed stream.");
     } catch (IOException $ioe) {
         // exception is expected
     }
 }
コード例 #2
0
 private function getStream()
 {
     if (!$this->stream) {
         Assert::isNotNull($this->queue->getFileName());
         $this->stream = FileOutputStream::create($this->queue->getFileName(), true);
     }
     return $this->stream;
 }
コード例 #3
0
ファイル: JsonLogger.php プロジェクト: Ingewikkeld/phing
 /**
  * Fired when the build finishes, this adds the time taken and any
  * error stacktrace to the build element and writes the document to disk.
  *
  * @param BuildEvent $event An event with any relevant extra information.
  *                          Will not be <code>null</code>.
  * @throws BuildException
  */
 public function buildFinished(BuildEvent $event)
 {
     $elapsedTime = Phing::currentTimeMillis() - $this->getBuildTimerStart();
     $this->getBuildElement()->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime));
     if ($event->getException() != null) {
         $this->getBuildElement()->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->getMessage());
         $errText = $this->getDoc()->createCDATASection($event->getException()->getTraceAsString());
         $stacktrace = $this->getDoc()->createElement(XmlLogger::STACKTRACE_TAG);
         $stacktrace->appendChild($errText);
         $this->getBuildElement()->appendChild($stacktrace);
     }
     $this->getDoc()->appendChild($this->getBuildElement());
     $outFilename = $event->getProject()->getProperty("JsonLogger.file");
     if ($outFilename == null) {
         $outFilename = "log.json";
     }
     try {
         $stream = $this->getOut();
         if ($stream === null) {
             $stream = new FileOutputStream($outFilename);
         }
         $writer = new OutputStreamWriter($stream);
         $writer->write($this->xml2js(simplexml_import_dom($this->getDoc())));
         $writer->close();
     } catch (IOException $exc) {
         try {
             $stream->close();
             // in case there is a stream open still ...
         } catch (Exception $x) {
         }
         throw new BuildException("Unable to write log file.", $exc);
     }
     // cleanup:remove the buildElement
     $this->setBuildElement(null);
     array_pop($this->getElementStack());
     array_pop($this->getTimesStack());
 }
コード例 #4
0
ファイル: XmlLogger.php プロジェクト: codebubb/web_ssh
 /**
  * Fired when the build finishes, this adds the time taken and any
  * error stacktrace to the build element and writes the document to disk.
  *
  * @param BuildEvent $event An event with any relevant extra information.
  *                          Will not be <code>null</code>.
  * @throws BuildException
  */
 public function buildFinished(BuildEvent $event)
 {
     $elapsedTime = Phing::currentTimeMillis() - $this->buildTimerStart;
     $this->buildElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime));
     if ($event->getException() != null) {
         $this->buildElement->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->getMessage());
         $errText = $this->doc->createCDATASection($event->getException()->getTraceAsString());
         $stacktrace = $this->doc->createElement(XmlLogger::STACKTRACE_TAG);
         $stacktrace->appendChild($errText);
         $this->buildElement->appendChild($stacktrace);
     }
     $this->doc->appendChild($this->buildElement);
     $outFilename = $event->getProject()->getProperty("XmlLogger.file");
     if ($outFilename == null) {
         $outFilename = "log.xml";
     }
     try {
         $stream = $this->out;
         if ($stream === null) {
             $stream = new FileOutputStream($outFilename);
         }
         // Yes, we could just stream->write() but this will eventually be the better
         // way to do this (when we need to worry about charset conversions.
         $writer = new OutputStreamWriter($stream);
         $writer->write($this->doc->saveXML());
         $writer->close();
     } catch (IOException $exc) {
         try {
             $stream->close();
             // in case there is a stream open still ...
         } catch (Exception $x) {
         }
         throw new BuildException("Unable to write log file.", $exc);
     }
     // cleanup:remove the buildElement
     $this->buildElement = null;
     array_pop($this->elementStack);
     array_pop($this->timesStack);
 }
コード例 #5
0
 public function doubleClose()
 {
     with($stream = new FileOutputStream($this->file));
     $stream->close();
     $stream->close();
 }
コード例 #6
0
 public function __construct(CachePeer $peer, $logfile, $isWeb = true, $appendFile = true)
 {
     $this->peer = $peer;
     $this->isWeb = $isWeb;
     $this->logger = StreamLogger::create()->setOutputStream(FileOutputStream::create($logfile, $appendFile));
 }