Currently, it only writes which targets are being executed, and any messages that get logged.
See also: BuildEvent
Author: Andreas Aderhold (andi@binarycloud.com)
Inheritance: implements StreamRequiredBuildLogger
 /**
  * Construct new HtmlColorLogger
  * Perform initializations that cannot be done in var declarations.
  */
 public function __construct()
 {
     parent::__construct();
     $this->errColor = self::PREFIX . self::CLASS_ERR . self::SUFFIX;
     $this->warnColor = self::PREFIX . self::CLASS_WARN . self::SUFFIX;
     $this->infoColor = self::PREFIX . self::CLASS_INFO . self::SUFFIX;
     $this->verboseColor = self::PREFIX . self::CLASS_VERBOSE . self::SUFFIX;
     $this->debugColor = self::PREFIX . self::CLASS_DEBUG . self::SUFFIX;
 }
Exemple #2
0
 /**
  * Sends the mail
  *
  * @see DefaultLogger#buildFinished
  * @param BuildEvent $event
  */
 public function buildFinished(BuildEvent $event)
 {
     parent::buildFinished($event);
     if (empty($this->_tolist)) {
         return;
     }
     $hdrs = array('From' => $this->_from, 'Subject' => $this->_subject . (empty($event) ? " (build succesful)" : " (build failed)"));
     $mail = Mail::factory('mail');
     $mail->send($this->_tolist, $hdrs, $this->_mailMessage);
 }
 function messageLogged(BuildEvent $event)
 {
     if ($event->getPriority() > $this->msgOutputLevel || null === $event->getMessage() || trim($event->getMessage() === "")) {
         return;
     }
     if ($this->targetName !== null) {
         print $this->lSep . "Target: " . $this->targetName . $this->lSep;
         $this->targetName = null;
     }
     parent::messageLogged($event);
 }
Exemple #4
0
 function messageLogged(BuildEvent $event)
 {
     if ($event->getPriority() > $this->msgOutputLevel || null === $event->getMessage() || trim($event->getMessage() === "")) {
         return;
     }
     if ($this->targetName !== null) {
         $msg = PHP_EOL . $event->getProject()->getName() . ' > ' . $this->targetName . ':' . PHP_EOL;
         $this->printMessage($msg, $this->out, $event->getPriority());
         $this->targetName = null;
     }
     parent::messageLogged($event);
 }
 /**
  * Sends the mail
  *
  * @see DefaultLogger#buildFinished
  * @param BuildEvent $event
  */
 public function buildFinished(BuildEvent $event)
 {
     parent::buildFinished($event);
     $project = $event->getProject();
     $properties = $project->getProperties();
     $filename = $properties['phing.log.mail.properties.file'];
     // overlay specified properties file (if any), which overrides project
     // settings
     $fileProperties = new Properties();
     $file = new PhingFile($filename);
     try {
         $fileProperties->load($file);
     } catch (IOException $ioe) {
         // ignore because properties file is not required
     }
     foreach ($fileProperties as $key => $value) {
         $properties['key'] = $project->replaceProperties($value);
     }
     $success = $event->getException() === null;
     $prefix = $success ? 'success' : 'failure';
     try {
         $notify = StringHelper::booleanValue($this->getValue($properties, $prefix . '.notify', 'on'));
         if (!$notify) {
             return;
         }
         if (is_string(Phing::getDefinedProperty('phing.log.mail.subject'))) {
             $defaultSubject = Phing::getDefinedProperty('phing.log.mail.subject');
         } else {
             $defaultSubject = $success ? 'Build Success' : 'Build Failure';
         }
         $hdrs = array();
         $hdrs['From'] = $this->getValue($properties, 'from', $this->from);
         $hdrs['Reply-To'] = $this->getValue($properties, 'replyto', '');
         $hdrs['Cc'] = $this->getValue($properties, $prefix . '.cc', '');
         $hdrs['Bcc'] = $this->getValue($properties, $prefix . '.bcc', '');
         $hdrs['Body'] = $this->getValue($properties, $prefix . '.body', '');
         $hdrs['Subject'] = $this->getValue($properties, $prefix . '.subject', $defaultSubject);
         $tolist = $this->getValue($properties, $prefix . '.to', $this->tolist);
     } catch (BadMethodCallException $e) {
         $project->log($e->getMessage(), Project::MSG_WARN);
     }
     if (empty($tolist)) {
         return;
     }
     $mail = Mail::factory('mail');
     $mail->send($tolist, $hdrs, $this->mailMessage);
 }
Exemple #6
0
 /**
  * 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());
 }
 /**
  *  Logs whether the build succeeded or failed, and any errors that
  *  occured during the build. Also outputs the total build-time.
  *
  * @param  BuildEvent  The BuildEvent
  *
  * @see    BuildEvent::getException()
  */
 public function buildFinished(BuildEvent $event)
 {
     $error = $event->getException();
     if ($error === null) {
         $msg = "Finished successful build.";
     } else {
         $msg = "Build failed. [reason: " . $error->getMessage() . "]";
     }
     $this->logger()->log($msg . " Total time: " . DefaultLogger::formatTime(Phing::currentTimeMillis() - $this->startTime));
 }
Exemple #8
0
 /**
  * Creates the default build logger for sending build events to the log.
  * @return BuildLogger The created Logger
  */
 private function createLogger()
 {
     if ($this->loggerClassname !== null) {
         self::import($this->loggerClassname);
         // get class name part
         $classname = self::import($this->loggerClassname);
         $logger = new $classname();
         if (!$logger instanceof BuildLogger) {
             throw new BuildException($classname . ' does not implement the BuildLogger interface.');
         }
     } else {
         require_once 'phing/listener/DefaultLogger.php';
         $logger = new DefaultLogger();
     }
     $logger->setMessageOutputLevel(self::$msgOutputLevel);
     $logger->setOutputStream(self::$out);
     $logger->setErrorStream(self::$err);
     return $logger;
 }
Exemple #9
0
 /**
  * Fired when a task finishes building, this adds the time taken
  * to the appropriate task element in the log.
  *
  * @param BuildEvent $event An event with any relevant extra information.
  *                          Will not be <code>null</code>.
  */
 public function taskFinished(BuildEvent $event)
 {
     $taskTimerStart = array_pop($this->timesStack);
     $taskElement = array_pop($this->elementStack);
     $elapsedTime = Phing::currentTimeMillis() - $taskTimerStart;
     $taskElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime));
     $parentElement = $this->elementStack[count($this->elementStack) - 1];
     $parentElement->appendChild($taskElement);
 }
 /**
  * Construct new AnsiColorLogger
  * Perform initializations that cannot be done in var declarations.
  */
 public function __construct()
 {
     parent::__construct();
     $this->errColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_RED . self::SUFFIX;
     $this->warnColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_MAGENTA . self::SUFFIX;
     $this->infoColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_CYAN . self::SUFFIX;
     $this->verboseColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_GREEN . self::SUFFIX;
     $this->debugColor = self::PREFIX . self::ATTR_DIM . self::SEPARATOR . self::FG_BLUE . self::SUFFIX;
 }
Exemple #11
0
 /**
  * Creates the default build logger for sending build events to the log.
  * @return BuildListener The created Logger
  */
 private function createLogger()
 {
     if ($this->loggerClassname !== null) {
         self::import($this->loggerClassname);
         // get class name part
         $classname = self::import($this->loggerClassname);
         $logger = new $classname();
     } else {
         require_once 'phing/listener/DefaultLogger.php';
         $logger = new DefaultLogger();
     }
     $logger->setMessageOutputLevel(self::$msgOutputLevel);
     return $logger;
 }
 public function buildFinished(BuildEvent $event)
 {
     if ($event->getException() != null) {
         parent::buildFinished($event);
     }
 }
 /**
  * Fired when a task finishes building, this adds the time taken
  * to the appropriate task element in the log.
  *
  * @param BuildEvent An event with any relevant extra information.
  *              Will not be <code>null</code>.
  */
 function taskFinished(BuildEvent $event)
 {
     $task = $event->getTask();
     $elapsedTime = Phing::currentTimeMillis() - $this->taskTimerStart;
     $this->taskElement->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::_formatTime($elapsedTime));
     $this->targetElement->appendChild($this->taskElement);
 }
 /**
  * Sets the error stream for the logging.
  *
  * @param      OutputStream The error stream.
  *
  * @see        DefaultLogger::setOutputStream()
  *
  * @author     Noah Fontes <*****@*****.**>
  * @since      1.0.0
  */
 public function setErrorStream(OutputStream $error)
 {
     parent::setErrorStream($error);
     $this->logger->setErrorStream($error);
 }
 public function testError()
 {
     $logger = new DefaultLogger();
     $this->expectOutputString("[" . date('Y-m-d H:i:s') . "][ERROR] test msg\n");
     $logger->error('test msg');
 }
 /**
  * This is an override point: the message that indicates that a build succeeded.
  * Subclasses can change/enhance the message.
  *
  * @return string The classic "BUILD SUCCESSFUL" plus a timestamp
  */
 protected function getBuildSuccessfulMessage()
 {
     return parent::getBuildSuccessfulMessage() . self::$SPACER . date('n/d/Y h:m a');
 }