[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/vendor/phing/listener/ -> DefaultLogger.php (source)

   1  <?php
   2  /*
   3   *  $Id: DefaultLogger.php 3076 2006-12-18 08:52:12Z fabien $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://phing.info>.
  20   */
  21   
  22  require_once 'phing/BuildListener.php';
  23  include_once 'phing/BuildEvent.php';
  24  
  25  /**
  26   *  Writes a build event to the console.
  27   *
  28   *  Currently, it only writes which targets are being executed, and
  29   *  any messages that get logged.
  30   *
  31   *  @author    Andreas Aderhold <andi@binarycloud.com>
  32   *  @copyright © 2001,2002 THYRELL. All rights reserved
  33   *  @version   $Revision: 1.11 $ $Date: 2005/08/25 19:33:43 $
  34   *  @see       BuildEvent
  35   *  @package   phing.listener
  36   */
  37  class DefaultLogger implements BuildListener {
  38  
  39      /**
  40       *  Size of the left column in output. The default char width is 12.
  41       *  @var int
  42       */
  43      const LEFT_COLUMN_SIZE = 12;
  44  
  45      /**
  46       *  The message output level that should be used. The default is
  47       *  <code>PROJECT_MSG_VERBOSE</code>.
  48       *  @var int
  49       */
  50      protected $msgOutputLevel = PROJECT_MSG_ERR;
  51  
  52      /**
  53       *  Time that the build started
  54       *  @var int
  55       */
  56      protected $startTime;
  57  
  58      /**
  59       *  Char that should be used to seperate lines. Default is the system
  60       *  property <em>line.seperator</em>.
  61       *  @var string
  62       */
  63      protected $lSep;
  64  
  65      /**
  66       *  Construct a new default logger.
  67       */
  68      public function __construct() {
  69          $this->lSep = Phing::getProperty("line.separator");
  70      }
  71  
  72      /**
  73       *  Set the msgOutputLevel this logger is to respond to.
  74       *
  75       *  Only messages with a message level lower than or equal to the given
  76       *  level are output to the log.
  77       *
  78       *  <p> Constants for the message levels are in Project.php. The order of
  79       *  the levels, from least to most verbose, is:
  80       *
  81       *  <ul>
  82       *    <li>PROJECT_MSG_ERR</li>
  83       *    <li>PROJECT_MSG_WARN</li>
  84       *    <li>PROJECT_MSG_INFO</li>
  85       *    <li>PROJECT_MSG_VERBOSE</li>
  86       *    <li>PROJECT_MSG_DEBUG</li>
  87       *  </ul>
  88       *
  89       *  The default message level for DefaultLogger is PROJECT_MSG_ERR.
  90       *
  91       *  @param  integer  the logging level for the logger.
  92       *  @access public
  93       */
  94      function setMessageOutputLevel($level) {
  95          $this->msgOutputLevel = (int) $level;
  96      }
  97  
  98      /**
  99      *  Sets the start-time when the build started. Used for calculating
 100      *  the build-time.
 101      *
 102      *  @param  object  The BuildEvent
 103      *  @access public
 104      */
 105  
 106      function buildStarted(BuildEvent $event) {
 107          $this->startTime = Phing::currentTimeMillis();
 108          if ($this->msgOutputLevel >= PROJECT_MSG_INFO) {
 109              $this->printMessage("Buildfile: ".$event->getProject()->getProperty("phing.file"), PROJECT_MSG_INFO);
 110          }
 111      }
 112  
 113      /**
 114       *  Prints whether the build succeeded or failed, and any errors that
 115       *  occured during the build. Also outputs the total build-time.
 116       *
 117       *  @param  object  The BuildEvent
 118       *  @access public
 119       *  @see    BuildEvent::getException()
 120       */
 121      function buildFinished(BuildEvent $event) {
 122          $error = $event->getException();
 123          if ($error === null) {
 124              print($this->lSep . "BUILD FINISHED" . $this->lSep);
 125          } else {
 126              print($this->lSep . "BUILD FAILED" . $this->lSep);
 127              if (PROJECT_MSG_VERBOSE <= $this->msgOutputLevel || !($error instanceof BuildException)) {
 128                  print($error->__toString().$this->lSep);
 129              } else {
 130                  print($error->getMessage());
 131              }
 132          }
 133          print($this->lSep . "Total time: " .$this->_formatTime(Phing::currentTimeMillis() - $this->startTime) . $this->lSep);
 134      }
 135  
 136      /**
 137       *  Prints the current target name
 138       *
 139       *  @param  object  The BuildEvent
 140       *  @access public
 141       *  @see    BuildEvent::getTarget()
 142       */
 143      function targetStarted(BuildEvent $event) {
 144          if (PROJECT_MSG_INFO <= $this->msgOutputLevel) {
 145              print($this->lSep . $event->getProject()->getName() . ' > ' . $event->getTarget()->getName() . ':' . $this->lSep);
 146          }
 147      }
 148  
 149      /**
 150       *  Fired when a target has finished. We don't need specific action on this
 151       *  event. So the methods are empty.
 152       *
 153       *  @param  object  The BuildEvent
 154       *  @access public
 155       *  @see    BuildEvent::getException()
 156       */
 157      function targetFinished(BuildEvent $event) {}
 158  
 159      /**
 160       *  Fired when a task is started. We don't need specific action on this
 161       *  event. So the methods are empty.
 162       *
 163       *  @param  object  The BuildEvent
 164       *  @access public
 165       *  @see    BuildEvent::getTask()
 166       */
 167      function taskStarted(BuildEvent $event) {}
 168  
 169      /**
 170       *  Fired when a task has finished. We don't need specific action on this
 171       *  event. So the methods are empty.
 172       *
 173       *  @param  object  The BuildEvent
 174       *  @access public
 175       *  @see    BuildEvent::getException()
 176       */
 177      function taskFinished(BuildEvent $event) {}
 178  
 179      /**
 180       *  Print a message to the stdout.
 181       *
 182       *  @param  object  The BuildEvent
 183       *  @access public
 184       *  @see    BuildEvent::getMessage()
 185       */
 186      function messageLogged(BuildEvent $event) {
 187          if ($event->getPriority() <= $this->msgOutputLevel) {
 188              $msg = "";
 189              if ($event->getTask() !== null) {
 190                  $name = $event->getTask();
 191                  $name = $name->getTaskName();
 192                  $msg = str_pad("[$name] ", self::LEFT_COLUMN_SIZE, " ", STR_PAD_LEFT);
 193                  #for ($i=0; $i < ($this->LEFT_COLUMN_SIZE - strlen($msg)); ++$i) {
 194                  #    print(" ");
 195                  #}
 196                  #print($msg);
 197              }
 198              $msg .= $event->getMessage();
 199              $this->printMessage($msg, $event->getPriority());
 200          }
 201      }
 202  
 203      /**
 204       *  Formats a time micro integer to human readable format.
 205       *
 206       *  @param  integer The time stamp
 207       *  @access private
 208       */
 209      function _formatTime($micros) {
 210          $seconds = $micros;
 211          $minutes = $seconds / 60;
 212          if ($minutes > 1) {
 213              return sprintf("%1.0f minute%s %0.2f second%s",
 214                                      $minutes, ($minutes === 1 ? " " : "s "),
 215                                      $seconds - floor($seconds/60) * 60, ($seconds%60 === 1 ? "" : "s"));
 216          } else {
 217              return sprintf("%0.4f second%s", $seconds, ($seconds%60 === 1 ? "" : "s"));
 218          }
 219      }
 220      
 221      /**
 222       * Prints a message to console.
 223       * 
 224       * @param string $message  The message to print. 
 225       *                 Should not be <code>null</code>.
 226       * @param int $priority The priority of the message. 
 227       *                 (Ignored in this implementation.)
 228       * @return void
 229       */
 230      protected function printMessage($message, $priority) {
 231          print($message . $this->lSep);
 232      }    
 233  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7