Changeset 147

Show
Ignore:
Timestamp:
02/06/07 20:32:22 (2 years ago)
Author:
hans
Message:
  • Fixes #65: Convert all loggers/listeners to use streams.
  • Also cleans up phing.system.io package contents.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/classes/phing/BuildLogger.php

    r123 r147  
    11<?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 
     22require_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 */ 
     39interface BuildLogger extends BuildListener { 
     40 
    241        /** 
    3          * $Id$ 
     42         * Sets the min log level that this logger should respect. 
     43         *  
     44         * Messages below this level are ignored. 
    445         * 
    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.). 
    2055         */ 
    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  
    4242include_once 'phing/util/StringHelper.php'; 
    4343include_once 'phing/system/io/PhingFile.php'; 
     44include_once 'phing/system/io/OutputStream.php'; 
     45include_once 'phing/system/io/FileOutputStream.php'; 
    4446include_once 'phing/system/io/FileReader.php'; 
    4547include_once 'phing/system/util/Register.php'; 
     
    9294    /** Indicates we should only parse and display the project help information */ 
    9395    private $projectHelp = false; 
    94      
     96         
    9597    /** Used by utility function getResourcePath() */ 
    9698    private static $importPaths; 
     
    110112        /** Array of captured PHP errors */ 
    111113        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                 
    130130    /**  
    131131     * Entry point allowing for more options from other front ends. 
     
    147147            $m->execute($args); 
    148148        } catch (Exception $exc) { 
     149                self::handleLogfile(); // clean up log file before attempting to print message 
    149150            $m->printMessage($exc); 
    150151            self::halt(-1); // Parameter error 
     
    163164            $m->runBuild(); 
    164165        } catch(Exception $exc) { 
     166                self::handleLogfile(); 
    165167            self::halt(1); // Errors occured 
    166168        } 
    167169         
    168170        // 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        } 
    170241    } 
    171242     
     
    222293                self::$msgOutputLevel = Project::MSG_DEBUG; 
    223294            } elseif ($arg == "-logfile") { 
    224                 try { // try to set logfile 
    225                         // TODO - This is slated to be overhauled for 2.3.0 
     295                try { 
    226296                        // see: http://phing.info/trac/ticket/65 
    227297                    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)
    230300                    } else { 
    231301                        $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; 
    233306                    } 
    234307                } 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)
    237310                } 
    238311            } elseif ($arg == "-buildfile" || $arg == "-file" || $arg == "-f") { 
    239312                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)
    242315                } else { 
    243316                    $this->buildFile = new PhingFile($args[++$i]); 
     
    245318            } elseif ($arg == "-listener") { 
    246319                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)
    249322                } else { 
    250323                    $this->listeners[] = $args[++$i]; 
     
    263336            } elseif ($arg == "-logger") { 
    264337                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)
    267340                } else { 
    268341                    $this->loggerClassname = $args[++$i]; 
     
    273346                } 
    274347                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)
    277350                } else { 
    278351                    $this->inputHandlerClassname = $args[++$i]; 
    279352                } 
    280             } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l") { 
     353            } elseif ($arg == "-projecthelp" || $arg == "-targets" || $arg == "-list" || $arg == "-l" || $arg == "-p") { 
    281354                // set the flag to display the targets and quit 
    282355                $this->projectHelp = true; 
     
    290363            } elseif (substr($arg,0,1) == "-") { 
    291364                // 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(); 
    294367                return; 
    295368            } else { 
     
    327400     * @return PhingFile Parent file or null if none 
    328401     */ 
    329     function _getParentFile(PhingFile $file) { 
     402    private function _getParentFile(PhingFile $file) { 
    330403        $filename = $file->getAbsolutePath(); 
    331404        $file     = new PhingFile($filename); 
     
    333406 
    334407        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")); 
    336409        } 
    337410 
     
    353426     * @throws BuildException    Failed to locate a build file 
    354427     */ 
    355     function _findBuildFile($start, $suffix) { 
     428    private function _findBuildFile($start, $suffix) { 
    356429        if (self::$msgOutputLevel >= Project::MSG_INFO) { 
    357             print("Searching for $suffix ...\n"); 
     430               self::$out->write("Searching for $suffix ..." . self::getProperty("line.separator")); 
    358431        } 
    359432        $startf = new PhingFile($start); 
     
    528601    /** 
    529602     * Creates the default build logger for sending build events to the log. 
    530      * @return BuildListener The created Logger 
     603     * @return BuildLogger The created Logger 
    531604     */ 
    532605    private function createLogger() { 
     
    541614        } 
    542615        $logger->setMessageOutputLevel(self::$msgOutputLevel); 
     616        $logger->setOutputStream(self::$out); 
     617        $logger->setErrorStream(self::$err); 
    543618        return $logger; 
    544619    } 
     
    655730         
    656731    /**  Prints the usage of how to use this class */ 
    657     function printUsage() { 
     732    public static function printUsage() { 
    658733        $lSep = self::getProperty("line.separator"); 
    659734        $msg = ""; 
     
    675750        $msg .= $lSep; 
    676751        $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     */ 
    684767    function getPhingVersion() { 
    685768                $versionPath = self::getResourcePath("phing/etc/VERSION.TXT"); 
     
    696779            $phingVersion = $buffer; 
    697780        } 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"); 
    700782        }         
    701783        return $phingVersion; 
    702784    } 
    703785 
    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) { 
    706790        if ($project->getDescription() !== null) { 
    707             print($project->getDescription()."\n"); 
     791            self::$out->write($project->getDescription() . self::getProperty("line.separator")); 
    708792        } 
    709793    } 
     
    807891        } 
    808892        if ($total > 0) { 
    809           print $msg . $lSep
    810         }  
     893          self::$out->write($msg . $lSep)
     894        } 
    811895   } 
    812896    
     
    870954            $new_parts = array_diff($add_parts, $curr_parts); 
    871955            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                 } 
    875956                ini_set('include_path', implode(PATH_SEPARATOR, array_merge($new_parts, $curr_parts))); 
    876957            } 
     
    880961         
    881962        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        } 
    895970   } 
    896971    
     
    11031178         
    11041179        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"); 
    11061181            self::halt(-1); 
    11071182        } 
     
    11481223        
    11491224        register_shutdown_function(array('Phing', 'shutdown')); 
    1150  
     1225         
     1226        // setup STDOUT and STDERR defaults 
     1227                self::initializeOutputStreams(); 
     1228                 
    11511229        // some init stuff 
    11521230        self::getTimer()->start(); 
     
    11701248     */ 
    11711249    public static function shutdown($exitcode = 0) { 
    1172         //print("[AUTOMATIC SYSTEM SHUTDOWN]\n"); 
    11731250        self::getTimer()->stop(); 
    11741251        exit($exitcode); // final point where everything stops 
  • trunk/classes/phing/filters/XincludeFilter.php

    r144 r147  
    7777        } 
    7878        
    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); 
    8080         
    8181        $out = ''; 
  • trunk/classes/phing/filters/util/IniFileTokenReader.php

    r123 r147  
    5050     * 
    5151     * @throws  IOException     On error 
     52     * @return Token 
    5253     */ 
    5354    function readToken() { 
  • trunk/classes/phing/listener/AnsiColorLogger.php

    r144 r147  
    199199    /** 
    200200     * @see DefaultLogger#printMessage 
     201     * @param string $message 
     202     * @param OutputStream $stream 
     203     * @param int $priority 
    201204     */ 
    202     protected final function printMessage($message, $priority) { 
    203      
     205    protected final function printMessage($message, OutputStream $stream, $priority) { 
    204206        if ($message !== null) { 
    205207         
     
    226228                    break; 
    227229            } 
    228             print($message."\n"); 
     230             
     231            $stream->write($message . $this->lSep); 
    229232        } 
    230233    } 
  • trunk/classes/phing/listener/DefaultLogger.php

    r144 r147  
    2020 */ 
    2121  
    22 require_once 'phing/BuildListener.php'; 
     22require_once 'phing/BuildLogger.php'; 
    2323include_once 'phing/BuildEvent.php'; 
    2424 
     
    3535 *  @package   phing.listener 
    3636 */ 
    37 class DefaultLogger implements BuildListener { 
     37class DefaultLogger implements BuildLogger { 
    3838 
    3939    /** 
     
    6262     */ 
    6363    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; 
    6474 
    6575    /** 
     
    8999     *  The default message level for DefaultLogger is Project::MSG_ERR. 
    90100     * 
    91      * @param  integer  the logging level for the logger. 
    92      * @access public 
    93      */ 
    94     function setMessageOutputLevel($level) { 
     101     * @param int $level The logging level for the logger. 
     102     * @see BuildLogger#setMessageOutputLevel() 
     103     */ 
     104    public function setMessageOutputLevel($level) { 
    95105        $this->msgOutputLevel = (int) $level; 
    96106    } 
    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     
    98126    /** 
    99127    *  Sets the start-time when the build started. Used for calculating 
     
    103131    *  @access public 
    104132    */ 
    105  
    106     function buildStarted(BuildEvent $event) { 
     133    public function buildStarted(BuildEvent $event) { 
    107134        $this->startTime = Phing::currentTimeMillis(); 
    108135        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); 
    110137        } 
    111138    } 
     
    116143     * 
    117144     *  @param  object  The BuildEvent 
    118      *  @access public 
    119145     *  @see    BuildEvent::getException() 
    120146     */ 
    121     function buildFinished(BuildEvent $event) { 
     147    public function buildFinished(BuildEvent $event) { 
    122148        $error = $event->getException(); 
    123149        if ($error === null) { 
    124             print($this->lSep . "BUILD FINISHED" . $this->lSep)
     150            $msg = $this->lSep . $this->getBuildSuccessfulMessage() . $this->lSep
    125151        } else { 
    126             print($this->lSep . "BUILD FAILED" . $this->lSep)
     152            $msg = $this->lSep . $this->getBuildFailedMessage() . $this->lSep
    127153            if (Project::MSG_VERBOSE <= $this->msgOutputLevel || !($error instanceof BuildException)) { 
    128                 print($error->__toString().$this->lSep)
     154                $msg .= $error->__toString().$this->lSep
    129155            } else { 
    130                 print($error->getMessage()); 
     156                $msg .= $error->getMessage(); 
    131157            } 
    132158        } 
    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     
    136184    /** 
    137185     *  Prints the current target name 
     
    141189     *  @see    BuildEvent::getTarget() 
    142190     */ 
    143     function targetStarted(BuildEvent $event) { 
     191    public function targetStarted(BuildEvent $event) { 
    144192        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()); 
    146195        } 
    147196    } 
     
    152201     * 
    153202     *  @param  object  The BuildEvent 
    154      *  @access public 
    155203     *  @see    BuildEvent::getException() 
    156204     */ 
    157     function targetFinished(BuildEvent $event) {} 
     205    public function targetFinished(BuildEvent $event) {} 
    158206 
    159207    /** 
     
    165213     *  @see    BuildEvent::getTask() 
    166214     */ 
    167     function taskStarted(BuildEvent $event) {} 
     215    public function taskStarted(BuildEvent $event) {} 
    168216 
    169217    /** 
     
    175223     *  @see    BuildEvent::getException() 
    176224     */ 
    177     function taskFinished(BuildEvent $event) {} 
     225    public function taskFinished(BuildEvent $event) {} 
    178226 
    179227    /** 
     
    184232     *  @see    BuildEvent::getMessage() 
    185233     */ 
    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) { 
    188237            $msg = ""; 
    189238            if ($event->getTask() !== null) { 
     
    191240                $name = $name->getTaskName(); 
    192241                $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); 
    197242            } 
     243             
    198244            $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            } 
    200251        } 
    201252    } 
     
    224275     * @param string $message  The message to print.  
    225276     *                 Should not be <code>null</code>. 
     277     * @param resource $stream The stream to use for message printing. 
    226278     * @param int $priority The priority of the message.  
    227279     *                 (Ignored in this implementation.) 
    228280     * @return void 
    229281     */ 
    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); 
    232284    }     
    233285} 
  • trunk/classes/phing/listener/NoBannerLogger.php

    r123 r147  
    2020 */ 
    2121 
    22 include_once 'phing/listener/DefaultLogger.php'; 
     22require_once 'phing/listener/DefaultLogger.php'; 
    2323 
    2424/** 
    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. 
    2826 * 
    2927 *  @author    Andreas Aderhold <andi@binarycloud.com> 
    30  *  @copyright © 2001,2002 THYRELL. All rights reserved 
     28 *  @copyright ᅵ 2001,2002 THYRELL. All rights reserved 
    3129 *  @version   $Revision: 1.4 $ $Date$ 
    3230 *  @package   phing.listener 
     
    3432class NoBannerLogger extends DefaultLogger { 
    3533 
    36     private $targetName = null; 
     34       private $targetName = null; 
    3735 
    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       
    4240 
    43     function targetFinished(BuildEvent $event) { 
    44         $this->targetName = null; 
    45    
     41       function targetFinished(BuildEvent $event) { 
     42               $this->targetName = null; 
     43       
    4644 
    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                } 
    5356 
    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        } 
    6159} 
  • trunk/classes/phing/listener/PearLogListener.php

    r144 r147  
    2121  
    2222require_once 'phing/BuildListener.php'; 
    23 include_once 'phing/BuildEvent.php'; 
    24 require_once 'Log.php'; 
    2523 
    2624/** 
    27  * Writes log messages to PEAR Log. 
     25 * Writes build messages to PEAR Log. 
    2826 *  
    2927 * By default it will log to file in current directory w/ name 'phing.log'.  You can customize 
     
    4341 * @package   phing.listener 
    4442 */ 
    45 class PearLogger implements BuildListener { 
     43class PearLogListener implements BuildListener { 
    4644 
    4745    /** 
     
    5048     */ 
    5149    const LEFT_COLUMN_SIZE = 12; 
    52  
    53     /** 
    54      *  The message output level that should be used. The default is 
    55      *  <code>Project::MSG_VERBOSE</code>. 
    56      *  @var int 
    57      */ 
    58     protected $msgOutputLevel = Project::MSG_DEBUG; 
    5950 
    6051    /** 
     
    7970     */ 
    8071    protected $logConfigured = false; 
    81                
     72     
     73    /** 
     74     * @var Log PEAR Log object. 
     75     */ 
     76        protected $logger; 
     77         
    8278    /** 
    8379     * Configure the logger. 
    8480     */ 
    8581    protected function configureLogging() { 
    86      
    87         $logfile = Phing::getDefinedProperty('phing.listener.logfile'); 
    8882         
    8983        $type = Phing::getDefinedProperty('pear.log.type'); 
     
    9387         
    9488        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'; 
    10390        if ($ident === null) $ident = 'phing'; 
    10491        if ($conf === null) $conf = array(); 
     92         
     93        include_once 'Log.php'; 
     94        if (!class_exists('Log')) { 
     95          &n