Changeset 147
- Timestamp:
- 02/06/07 20:32:22 (2 years ago)
- Files:
-
- trunk/classes/phing/BuildLogger.php (moved) (moved from trunk/classes/phing/listener/BuildLogger.php) (1 diff)
- trunk/classes/phing/Phing.php (modified) (24 diffs)
- trunk/classes/phing/filters/XincludeFilter.php (modified) (1 diff)
- trunk/classes/phing/filters/util/IniFileTokenReader.php (modified) (1 diff)
- trunk/classes/phing/listener/AnsiColorLogger.php (modified) (2 diffs)
- trunk/classes/phing/listener/DefaultLogger.php (modified) (13 diffs)
- trunk/classes/phing/listener/NoBannerLogger.php (modified) (2 diffs)
- trunk/classes/phing/listener/PearLogListener.php (moved) (moved from trunk/classes/phing/listener/PearLogger.php) (11 diffs)
- trunk/classes/phing/listener/XmlLogger.php (modified) (1 diff)
- trunk/classes/phing/parser/ProjectConfigurator.php (modified) (1 diff)
- trunk/classes/phing/parser/TaskHandler.php (modified) (1 diff)
- trunk/classes/phing/system/io/BufferedReader.php (modified) (3 diffs)
- trunk/classes/phing/system/io/BufferedWriter.php (modified) (1 diff)
- trunk/classes/phing/system/io/FileInputStream.php (added)
- trunk/classes/phing/system/io/FileOutputStream.php (added)
- trunk/classes/phing/system/io/FileReader.php (modified) (1 diff)
- trunk/classes/phing/system/io/FileSystem.php (modified) (1 diff)
- trunk/classes/phing/system/io/FileWriter.php (modified) (2 diffs)
- trunk/classes/phing/system/io/FilterReader.php (modified) (2 diffs)
- trunk/classes/phing/system/io/InputStream.php (added)
- trunk/classes/phing/system/io/InputStreamReader.php (added)
- trunk/classes/phing/system/io/OutputStream.php (added)
- trunk/classes/phing/system/io/OutputStreamWriter.php (added)
- trunk/classes/phing/system/io/Reader.php (modified) (5 diffs)
- trunk/classes/phing/system/io/StringReader.php (modified) (1 diff)
- trunk/classes/phing/system/io/TokenReader.php (deleted)
- trunk/classes/phing/system/io/Writer.php (modified) (1 diff)
- trunk/classes/phing/system/util/Properties.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/classes/phing/BuildLogger.php
r123 r147 1 1 <?php 2 /* 3 * $Id$ 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 24 /** 25 * Interface for build loggers. 26 * 27 * Build loggers are build listeners but with some additional functionality: 28 * - They can be configured with a log level (below which they will ignore messages) 29 * - They have error and output streams 30 * 31 * Classes that implement a listener must implement this interface. 32 * 33 * @author Hans Lellelid <hans@xmpl.org> 34 * @version $Revision: 1.6 $ 35 * @see BuildEvent 36 * @see Project::addBuildListener() 37 * @package phing 38 */ 39 interface BuildLogger extends BuildListener { 40 2 41 /** 3 * $Id$ 42 * Sets the min log level that this logger should respect. 43 * 44 * Messages below this level are ignored. 4 45 * 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>. 46 * Constants for the message levels are in Project.php. The order of 47 * the levels, from least to most verbose, is: 48 * - Project::MSG_ERR 49 * - Project::MSG_WARN 50 * - Project::MSG_INFO 51 * - Project::MSG_VERBOSE 52 * - Project::MSG_DEBUG 53 * 54 * @param int $level The log level integer (e.g. Project::MSG_VERBOSE, etc.). 20 55 */ 21 22 require_once 'phing/BuildListener.php'; 23 /** 24 * Interface used by Phing Ant to log the build output. 25 * 26 * @author Michiel Rook <michiel.rook@gmail.com> 27 * @version $Id$ 28 * @package phing.listener 29 */ 30 interface BuildLogger extends BuildListener 31 { 32 /** 33 * Sets the highest level of message this logger should respond to. 34 * 35 * Only messages with a message level lower than or equal to the 36 * given level should be written to the log. 37 * 38 * @param int the logging level for the logger. 39 */ 40 function setMessageOutputLevel($level); 41 }; 42 ?> 56 public function setMessageOutputLevel($level); 57 58 /** 59 * Sets the standard output stream to use. 60 * @param OutputStream $output Configured output stream (e.g. STDOUT) for standard output. 61 */ 62 public function setOutputStream(OutputStream $output); 63 64 /** 65 * Sets the output stream to use for errors. 66 * @param OutputStream $err Configured output stream (e.g. STDERR) for errors. 67 */ 68 public function setErrorStream(OutputStream $err); 69 70 } trunk/classes/phing/Phing.php
r144 r147 42 42 include_once 'phing/util/StringHelper.php'; 43 43 include_once 'phing/system/io/PhingFile.php'; 44 include_once 'phing/system/io/OutputStream.php'; 45 include_once 'phing/system/io/FileOutputStream.php'; 44 46 include_once 'phing/system/io/FileReader.php'; 45 47 include_once 'phing/system/util/Register.php'; … … 92 94 /** Indicates we should only parse and display the project help information */ 93 95 private $projectHelp = false; 94 96 95 97 /** Used by utility function getResourcePath() */ 96 98 private static $importPaths; … … 110 112 /** Array of captured PHP errors */ 111 113 private static $capturedPhpErrors = array(); 112 113 /** 114 * Prints the message of the Exception if it's not null. 115 */ 116 function printMessage(Exception $t) { 117 print($t->getMessage() . "\n"); 118 if (self::getMsgOutputLevel() === Project::MSG_DEBUG) { 119 print($t->getTraceAsString()."\n"); 120 if ($t instanceof Exception) { 121 $c = $t->getCause(); 122 if ($c !== null) { 123 print("Wrapped exception trace:\n"); 124 print($c->getTraceAsString() . "\n"); 125 } 126 } 127 } // if output level is DEBUG 128 } 129 114 115 /** 116 * @var OUtputStream Stream for standard output. 117 */ 118 private static $out; 119 120 /** 121 * @var OutputStream Stream for error output. 122 */ 123 private static $err; 124 125 /** 126 * @var boolean Whether we are using a logfile. 127 */ 128 private static $isLogFileUsed = false; 129 130 130 /** 131 131 * Entry point allowing for more options from other front ends. … … 147 147 $m->execute($args); 148 148 } catch (Exception $exc) { 149 self::handleLogfile(); // clean up log file before attempting to print message 149 150 $m->printMessage($exc); 150 151 self::halt(-1); // Parameter error … … 163 164 $m->runBuild(); 164 165 } catch(Exception $exc) { 166 self::handleLogfile(); 165 167 self::halt(1); // Errors occured 166 168 } 167 169 168 170 // everything fine, shutdown 169 self::halt(0); // no errors, everything is cake 171 self::handleLogfile(); 172 self::halt(0); 173 } 174 175 /** 176 * Prints the message of the Exception if it's not null. 177 * @param Exception $t 178 */ 179 public static function printMessage(Exception $t) { 180 if (self::getMsgOutputLevel() <= Project::MSG_DEBUG) { 181 self::$err->write($t->__toString()); 182 } else { 183 self::$err->write($t->getMessage()); 184 } 185 } 186 187 /** 188 * Sets the stdout and stderr streams if they are not already set. 189 */ 190 private static function initializeOutputStreams() { 191 if (self::$out === null) { 192 self::$out = new OutputStream(fopen("php://stdout", "w")); 193 } 194 if (self::$err === null) { 195 self::$err = new OutputStream(fopen("php://stderr", "w")); 196 } 197 } 198 199 /** 200 * Sets the stream to use for standard (non-error) output. 201 * @param OutputStream $stream The stream to use for standard output. 202 */ 203 public static function setOutputStream(OutputStream $stream) { 204 self::$out = $stream; 205 } 206 207 /** 208 * Gets the stream to use for standard (non-error) output. 209 * @return OutputStream 210 */ 211 public static function getOutputStream() { 212 return self::$out; 213 } 214 215 /** 216 * Sets the stream to use for error output. 217 * @param OutputStream $stream The stream to use for error output. 218 */ 219 public static function setErrorStream(OutputStream $stream) { 220 self::$err = $stream; 221 } 222 223 /** 224 * Gets the stream to use for error output. 225 * @return OutputStream 226 */ 227 public static function getErrorStream() { 228 return self::$err; 229 } 230 231 /** 232 * Close logfiles, if we have been writing to them. 233 * 234 * @since Phing 2.3.0 235 */ 236 private static function handleLogfile() { 237 if (self::$isLogFileUsed) { 238 self::$err->close(); 239 self::$out->close(); 240 } 170 241 } 171 242 … … 222 293 self::$msgOutputLevel = Project::MSG_DEBUG; 223 294 } elseif ($arg == "-logfile") { 224 try { // try to set logfile 225 // TODO - This is slated to be overhauled for 2.3.0 295 try { 226 296 // see: http://phing.info/trac/ticket/65 227 297 if (!isset($args[$i+1])) { 228 print("You must specify a log file when using the -logfile argument\n");229 return;298 $msg = "You must specify a log file when using the -logfile argument\n"; 299 throw new BuildException($msg); 230 300 } else { 231 301 $logFile = new PhingFile($args[++$i]); 232 $this->setDefinedProperty('phing.listener.logfile', $logFile->getAbsolutePath()); 302 $out = new FileOutputStream($logFile); // overwrite 303 self::setOutputStream($out); 304 self::setErrorStream($out); 305 self::$isLogFileUsed = true; 233 306 } 234 307 } catch (IOException $ioe) { 235 print("Cannot write on the specified log file. Make sure the path exists and you have write permissions.\n");236 throw $ioe;308 $msg = "Cannot write on the specified log file. Make sure the path exists and you have write permissions."; 309 throw new BuildException($msg, $ioe); 237 310 } 238 311 } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") { 239 312 if (!isset($args[$i+1])) { 240 print("You must specify a buildfile when using the -buildfile argument\n");241 return;313 $msg = "You must specify a buildfile when using the -buildfile argument."; 314 throw new BuildException($msg); 242 315 } else { 243 316 $this->buildFile = new PhingFile($args[++$i]); … … 245 318 } elseif ($arg == "-listener") { 246 319 if (!isset($args[$i+1])) { 247 print("You must specify a listener class when using the -listener argument\n");248 return;320 $msg = "You must specify a listener class when using the -listener argument"; 321 throw new BuildException($msg); 249 322 } else { 250 323 $this->listeners[] = $args[++$i]; … … 263 336 } elseif ($arg == "-logger") { 264 337 if (!isset($args[$i+1])) { 265 print("You must specify a classname when using the -logger argument\n");266 return;338 $msg = "You must specify a classname when using the -logger argument"; 339 throw new BuildException($msg); 267 340 } else { 268 341 $this->loggerClassname = $args[++$i]; … … 273 346 } 274 347 if (!isset($args[$i+1])) { 275 print("You must specify a classname when using the -inputhandler argument\n");276 return;348 $msg = "You must specify a classname when using the -inputhandler argument"; 349 throw new BuildException($msg); 277 350 } else { 278 351 $this->inputHandlerClassname = $args[++$i]; 279 352 } 280 } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" ) {353 } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") { 281 354 // set the flag to display the targets and quit 282 355 $this->projectHelp = true; … … 290 363 } elseif (substr($arg,0,1) == "-") { 291 364 // we don't have any more args 292 print("Unknown argument: $arg\n");293 $this->printUsage();365 self::$err->write("Unknown argument: $arg"); 366 self::printUsage(); 294 367 return; 295 368 } else { … … 327 400 * @return PhingFile Parent file or null if none 328 401 */ 329 function _getParentFile(PhingFile $file) {402 private function _getParentFile(PhingFile $file) { 330 403 $filename = $file->getAbsolutePath(); 331 404 $file = new PhingFile($filename); … … 333 406 334 407 if ($filename !== null && self::$msgOutputLevel >= Project::MSG_VERBOSE) { 335 print("Searching in $filename\n");408 self::$out->write("Searching in $filename" . self::getProperty("line.separator")); 336 409 } 337 410 … … 353 426 * @throws BuildException Failed to locate a build file 354 427 */ 355 function _findBuildFile($start, $suffix) {428 private function _findBuildFile($start, $suffix) { 356 429 if (self::$msgOutputLevel >= Project::MSG_INFO) { 357 print("Searching for $suffix ...\n");430 self::$out->write("Searching for $suffix ..." . self::getProperty("line.separator")); 358 431 } 359 432 $startf = new PhingFile($start); … … 528 601 /** 529 602 * Creates the default build logger for sending build events to the log. 530 * @return BuildL istener The created Logger603 * @return BuildLogger The created Logger 531 604 */ 532 605 private function createLogger() { … … 541 614 } 542 615 $logger->setMessageOutputLevel(self::$msgOutputLevel); 616 $logger->setOutputStream(self::$out); 617 $logger->setErrorStream(self::$err); 543 618 return $logger; 544 619 } … … 655 730 656 731 /** Prints the usage of how to use this class */ 657 function printUsage() {732 public static function printUsage() { 658 733 $lSep = self::getProperty("line.separator"); 659 734 $msg = ""; … … 675 750 $msg .= $lSep; 676 751 $msg .= "Report bugs to <dev@phing.tigris.org>".$lSep; 677 print($msg); 678 } 679 680 function printVersion() { 681 print(self::getPhingVersion()."\n"); 682 } 683 752 self::$err->write($msg); 753 } 754 755 /** 756 * Prints the current Phing version. 757 */ 758 public static function printVersion() { 759 self::$out->write(self::getPhingVersion().self::getProperty("line.separator")); 760 } 761 762 /** 763 * Gets the current Phing version based on VERSION.TXT file. 764 * @return string 765 * @throws BuildException - if unable to find version file. 766 */ 684 767 function getPhingVersion() { 685 768 $versionPath = self::getResourcePath("phing/etc/VERSION.TXT"); … … 696 779 $phingVersion = $buffer; 697 780 } catch (IOException $iox) { 698 print("Can't read version information file\n"); 699 throw new BuildException("Build failed"); 781 throw new BuildException("Can't read version information file"); 700 782 } 701 783 return $phingVersion; 702 784 } 703 785 704 /** Print the project description, if any */ 705 function printDescription(Project $project) { 786 /** 787 * Print the project description, if any 788 */ 789 public static function printDescription(Project $project) { 706 790 if ($project->getDescription() !== null) { 707 print($project->getDescription()."\n");791 self::$out->write($project->getDescription() . self::getProperty("line.separator")); 708 792 } 709 793 } … … 807 891 } 808 892 if ($total > 0) { 809 print $msg . $lSep;810 } 893 self::$out->write($msg . $lSep); 894 } 811 895 } 812 896 … … 870 954 $new_parts = array_diff($add_parts, $curr_parts); 871 955 if ($new_parts) { 872 if (self::getMsgOutputLevel() === Project::MSG_DEBUG) {873 print("Phing::import() prepending new include_path components: " . implode(PATH_SEPARATOR, $new_parts) . "\n");874 }875 956 ini_set('include_path', implode(PATH_SEPARATOR, array_merge($new_parts, $curr_parts))); 876 957 } … … 880 961 881 962 if ($ret === false) { 882 $e = new BuildException("Error importing $path"); 883 if (self::getMsgOutputLevel() === Project::MSG_DEBUG) { 884 // We can't log this because listeners belong 885 // to projects. We'll just print it -- of course 886 // that isn't very compatible w/ other frontends (but 887 // there aren't any right now, so I'm not stressing) 888 print("Error importing $path\n"); 889 print($e->getTraceAsString()."\n"); 890 } 891 throw $e; 892 } 893 894 return; 963 $msg = "Error importing $path"; 964 if (self::getMsgOutputLevel() <= Project::MSG_DEBUG) { 965 $x = new Exception("for-path-trace-only"); 966 $msg .= $x->getTraceAsString(); 967 } 968 throw new BuildException($msg); 969 } 895 970 } 896 971 … … 1103 1178 1104 1179 if ($success === false) { 1105 print("SYSTEM FAILURE: Could not set PHP include path\n");1180 self::$err->write("SYSTEM FAILURE: Could not set PHP include path"); 1106 1181 self::halt(-1); 1107 1182 } … … 1148 1223 1149 1224 register_shutdown_function(array('Phing', 'shutdown')); 1150 1225 1226 // setup STDOUT and STDERR defaults 1227 self::initializeOutputStreams(); 1228 1151 1229 // some init stuff 1152 1230 self::getTimer()->start(); … … 1170 1248 */ 1171 1249 public static function shutdown($exitcode = 0) { 1172 //print("[AUTOMATIC SYSTEM SHUTDOWN]\n");1173 1250 self::getTimer()->stop(); 1174 1251 exit($exitcode); // final point where everything stops trunk/classes/phing/filters/XincludeFilter.php
r144 r147 77 77 } 78 78 79 $this->log("Transforming XML " . $this->in-> getResource() . " using Xinclude ", Project::MSG_VERBOSE);79 $this->log("Transforming XML " . $this->in->__toString() . " using Xinclude ", Project::MSG_VERBOSE); 80 80 81 81 $out = ''; trunk/classes/phing/filters/util/IniFileTokenReader.php
r123 r147 50 50 * 51 51 * @throws IOException On error 52 * @return Token 52 53 */ 53 54 function readToken() { trunk/classes/phing/listener/AnsiColorLogger.php
r144 r147 199 199 /** 200 200 * @see DefaultLogger#printMessage 201 * @param string $message 202 * @param OutputStream $stream 203 * @param int $priority 201 204 */ 202 protected final function printMessage($message, $priority) { 203 205 protected final function printMessage($message, OutputStream $stream, $priority) { 204 206 if ($message !== null) { 205 207 … … 226 228 break; 227 229 } 228 print($message."\n"); 230 231 $stream->write($message . $this->lSep); 229 232 } 230 233 } trunk/classes/phing/listener/DefaultLogger.php
r144 r147 20 20 */ 21 21 22 require_once 'phing/BuildL istener.php';22 require_once 'phing/BuildLogger.php'; 23 23 include_once 'phing/BuildEvent.php'; 24 24 … … 35 35 * @package phing.listener 36 36 */ 37 class DefaultLogger implements BuildL istener {37 class DefaultLogger implements BuildLogger { 38 38 39 39 /** … … 62 62 */ 63 63 protected $lSep; 64 65 /** 66 * @var OutputStream Stream to use for standard output. 67 */ 68 protected $out; 69 70 /** 71 * @var OutputStream Stream to use for error output. 72 */ 73 protected $err; 64 74 65 75 /** … … 89 99 * The default message level for DefaultLogger is Project::MSG_ERR. 90 100 * 91 * @param integer the logging level for the logger.92 * @access public93 */ 94 function setMessageOutputLevel($level) {101 * @param int $level The logging level for the logger. 102 * @see BuildLogger#setMessageOutputLevel() 103 */ 104 public function setMessageOutputLevel($level) { 95 105 $this->msgOutputLevel = (int) $level; 96 106 } 97 107 108 /** 109 * Sets the output stream. 110 * @param OutputStream $output 111 * @see BuildLogger#setOutputStream() 112 */ 113 public function setOutputStream(OutputStream $output) { 114 $this->out = $output; 115 } 116 117 /** 118 * Sets the error stream. 119 * @param OutputStream $err 120 * @see BuildLogger#setErrorStream() 121 */ 122 public function setErrorStream(OutputStream $err) { 123 $this->err = $err; 124 } 125 98 126 /** 99 127 * Sets the start-time when the build started. Used for calculating … … 103 131 * @access public 104 132 */ 105 106 function buildStarted(BuildEvent $event) { 133 public function buildStarted(BuildEvent $event) { 107 134 $this->startTime = Phing::currentTimeMillis(); 108 135 if ($this->msgOutputLevel >= Project::MSG_INFO) { 109 $this->printMessage("Buildfile: ".$event->getProject()->getProperty("phing.file"), Project::MSG_INFO);136 $this->printMessage("Buildfile: ".$event->getProject()->getProperty("phing.file"), $this->out, Project::MSG_INFO); 110 137 } 111 138 } … … 116 143 * 117 144 * @param object The BuildEvent 118 * @access public119 145 * @see BuildEvent::getException() 120 146 */ 121 function buildFinished(BuildEvent $event) {147 public function buildFinished(BuildEvent $event) { 122 148 $error = $event->getException(); 123 149 if ($error === null) { 124 print($this->lSep . "BUILD FINISHED" . $this->lSep);150 $msg = $this->lSep . $this->getBuildSuccessfulMessage() . $this->lSep; 125 151 } else { 126 print($this->lSep . "BUILD FAILED" . $this->lSep);152 $msg = $this->lSep . $this->getBuildFailedMessage() . $this->lSep; 127 153 if (Project::MSG_VERBOSE <= $this->msgOutputLevel || !($error instanceof BuildException)) { 128 print($error->__toString().$this->lSep);154 $msg .= $error->__toString().$this->lSep; 129 155 } else { 130 print($error->getMessage());156 $msg .= $error->getMessage(); 131 157 } 132 158 } 133 print($this->lSep . "Total time: " .self::formatTime(Phing::currentTimeMillis() - $this->startTime) . $this->lSep); 134 } 135 159 $msg .= $this->lSep . "Total time: " .self::formatTime(Phing::currentTimeMillis() - $this->startTime) . $this->lSep; 160 161 if ($error === null) { 162 $this->printMessage($msg, $this->out, Project::MSG_VERBOSE); 163 } else { 164 $this->printMessage($msg, $this->err, Project::MSG_ERR); 165 } 166 } 167 168 /** 169 * Get the message to return when a build failed. 170 * @return string The classic "BUILD FAILED" 171 */ 172 protected function getBuildFailedMessage() { 173 return "BUILD FAILED"; 174 } 175 176 /** 177 * Get the message to return when a build succeeded. 178 * @return string The classic "BUILD FINISHED" 179 */ 180 protected function getBuildSuccessfulMessage() { 181 return "BUILD FINISHED"; 182 } 183 136 184 /** 137 185 * Prints the current target name … … 141 189 * @see BuildEvent::getTarget() 142 190 */ 143 function targetStarted(BuildEvent $event) {191 public function targetStarted(BuildEvent $event) { 144 192 if (Project::MSG_INFO <= $this->msgOutputLevel) { 145 print($this->lSep . $event->getProject()->getName() . ' > ' . $event->getTarget()->getName() . ':' . $this->lSep); 193 $msg = $this->lSep . $event->getProject()->getName() . ' > ' . $event->getTarget()->getName() . ':' . $this->lSep; 194 $this->printMessage($msg, $this->out, $event->getPriority()); 146 195 } 147 196 } … … 152 201 * 153 202 * @param object The BuildEvent 154 * @access public155 203 * @see BuildEvent::getException() 156 204 */ 157 function targetFinished(BuildEvent $event) {}205 public function targetFinished(BuildEvent $event) {} 158 206 159 207 /** … … 165 213 * @see BuildEvent::getTask() 166 214 */ 167 function taskStarted(BuildEvent $event) {}215 public function taskStarted(BuildEvent $event) {} 168 216 169 217 /** … … 175 223 * @see BuildEvent::getException() 176 224 */ 177 function taskFinished(BuildEvent $event) {}225 public function taskFinished(BuildEvent $event) {} 178 226 179 227 /** … … 184 232 * @see BuildEvent::getMessage() 185 233 */ 186 function messageLogged(BuildEvent $event) { 187 if ($event->getPriority() <= $this->msgOutputLevel) { 234 public function messageLogged(BuildEvent $event) { 235 $priority = $event->getPriority(); 236 if ($priority <= $this->msgOutputLevel) { 188 237 $msg = ""; 189 238 if ($event->getTask() !== null) { … … 191 240 $name = $name->getTaskName(); 192 241 $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 242 } 243 198 244 $msg .= $event->getMessage(); 199 $this->printMessage($msg, $event->getPriority()); 245 246 if ($priority != Project::MSG_ERR) { 247 $this->printMessage($msg, $this->out, $priority); 248 } else { 249 $this->printMessage($msg, $this->err, $priority); 250 } 200 251 } 201 252 } … … 224 275 * @param string $message The message to print. 225 276 * Should not be <code>null</code>. 277 * @param resource $stream The stream to use for message printing. 226 278 * @param int $priority The priority of the message. 227 279 * (Ignored in this implementation.) 228 280 * @return void 229 281 */ 230 protected function printMessage($message, $priority) {231 print($message . $this->lSep);282 protected function printMessage($message, OutputStream $stream, $priority) { 283 $stream->write($message . $this->lSep); 232 284 } 233 285 } trunk/classes/phing/listener/NoBannerLogger.php
r123 r147 20 20 */ 21 21 22 include_once 'phing/listener/DefaultLogger.php';22 require_once 'phing/listener/DefaultLogger.php'; 23 23 24 24 /** 25 * Extends DefaultLogger to strip out empty targets. This logger is most 26 * commonly used and also enforced by the default phing invokation scripts 27 * in bin/. 25 * Extends DefaultLogger to strip out empty targets. 28 26 * 29 27 * @author Andreas Aderhold <andi@binarycloud.com> 30 * @copyright ©2001,2002 THYRELL. All rights reserved28 * @copyright ᅵ 2001,2002 THYRELL. All rights reserved 31 29 * @version $Revision: 1.4 $ $Date$ 32 30 * @package phing.listener … … 34 32 class NoBannerLogger extends DefaultLogger { 35 33 36 private $targetName = null;34 private $targetName = null; 37 35 38 function targetStarted(BuildEvent $event) {39 $target = $event->getTarget();40 $this->targetName = $target->getName();41 }36 function targetStarted(BuildEvent $event) { 37 $target = $event->getTarget(); 38 $this->targetName = $target->getName(); 39 } 42 40 43 function targetFinished(BuildEvent $event) {44 $this->targetName = null;45 }41 function targetFinished(BuildEvent $event) { 42 $this->targetName = null; 43 } 46 44 47 function messageLogged(BuildEvent $event) { 48 if ($event->getPriority() > $this->msgOutputLevel || 49 null === $event->getMessage() || 50 trim($event->getMessage() === "")) { 51 return; 52 } 45 function messageLogged(BuildEvent $event) { 46 47 if ($event->getPriority() > $this->msgOutputLevel || null === $event->getMessage() || trim($event->getMessage() === "")) { 48 return; 49 } 50 51 if ($this->targetName !== null) { 52 $msg = $this->lSep . $event->getProject()->getName() . ' > ' . $this->targetName . ':' . $this->lSep; 53 $this->printMessage($msg, $this->out, $event->getPriority()); 54 $this->targetName = null; 55 } 53 56 54 if ($this->targetName !== null) { 55 print($this->lSep . "Target: ".$this->targetName . $this->lSep); 56 $this->targetName = null; 57 } 58 59 parent::messageLogged($event); 60 } 57 parent::messageLogged($event); 58 } 61 59 } trunk/classes/phing/listener/PearLogListener.php
r144 r147 21 21 22 22 require_once 'phing/BuildListener.php'; 23 include_once 'phing/BuildEvent.php';24 require_once 'Log.php';25 23 26 24 /** 27 * Writes logmessages to PEAR Log.25 * Writes build messages to PEAR Log. 28 26 * 29 27 * By default it will log to file in current directory w/ name 'phing.log'. You can customize … … 43 41 * @package phing.listener 44 42 */ 45 class PearLog ger implements BuildListener {43 class PearLogListener implements BuildListener { 46 44 47 45 /** … … 50 48 */ 51 49 const LEFT_COLUMN_SIZE = 12; 52 53 /**54 * The message output level that should be used. The default is55 * <code>Project::MSG_VERBOSE</code>.56 * @var int57 */58 protected $msgOutputLevel = Project::MSG_DEBUG;59 50 60 51 /** … … 79 70 */ 80 71 protected $logConfigured = false; 81 72 73 /** 74 * @var Log PEAR Log object. 75 */ 76 protected $logger; 77 82 78 /** 83 79 * Configure the logger. 84 80 */ 85 81 protected function configureLogging() { 86 87 $logfile = Phing::getDefinedProperty('phing.listener.logfile');88 82 89 83 $type = Phing::getDefinedProperty('pear.log.type'); … … 93 87 94 88 if ($type === null) $type = 'file'; 95 96 if ($name === null) { 97 if ($logfile === null) { 98 $name = 'phing.log'; 99 } else { 100 $name = $logfile; 101 } 102 } 89 if ($name === null) $name = 'phing.log'; 103 90 if ($ident === null) $ident = 'phing'; 104 91 if ($conf === null) $conf = array(); 92 93 include_once 'Log.php'; 94 if (!class_exists('Log')) { 95 &n
