cvs: pear /Log Log.php package.php /Log/Log composite.php console.php file.php mail.php /Log/docs guide.txt /Log/tests console.phpt
| From: | Jon Parise | Date: | Fri, 02 Jan 2004 01:45:33 +0000 |
| Subject: | cvs: pear /Log Log.php package.php /Log/Log composite.php console.php file.php mail.php /Log/docs guide.txt /Log/tests console.phpt | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-15267@lists.php.net to get a copy of this message | ||
jon Thu Jan 1 20:45:33 2004 EDT
Modified files:
/pear/Log Log.php package.php
/pear/Log/Log composite.php console.php file.php mail.php
/pear/Log/docs guide.txt
/pear/Log/tests console.phpt
Log:
The public Log API has grown a flush() method. This allows buffered log
output to be explicitly flushed. At this time, the flush() method is only
implemented by the console, file and mail handlers.
Index: pear/Log/Log.php diff -u pear/Log/Log.php:1.41 pear/Log/Log.php:1.42 --- pear/Log/Log.php:1.41 Sat Nov 8 17:39:54 2003 +++ pear/Log/Log.php Thu Jan 1 20:45:30 2004 @@ -1,9 +1,9 @@ <?php /** - * $Header: /repository/pear/Log/Log.php,v 1.41 2003/11/08 22:39:54 jon Exp $ + * $Header: /repository/pear/Log/Log.php,v 1.42 2004/01/02 01:45:30 jon Exp $ * $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $ * - * @version $Revision: 1.41 $ + * @version $Revision: 1.42 $ * @package Log */ @@ -194,6 +194,15 @@ } /** + * Abstract implementation of the flush() method. + * @since Log 1.8.2 + */ + function flush() + { + return false; + } + + /** * Abstract implementation of the log() method. * @since Log 1.0 */ Index: pear/Log/package.php diff -u pear/Log/package.php:1.5 pear/Log/package.php:1.6 --- pear/Log/package.php:1.5 Mon Dec 29 02:27:16 2003 +++ pear/Log/package.php Thu Jan 1 20:45:30 2004 @@ -6,11 +6,14 @@ $version = '1.8.2'; $notes = <<<EOT Added a new 'null' log handler. +Added a flush() method to the public Log API. EOT; $changelog = <<<EOT A new 'null' log handler that simply consumes log events has been added. The 'null' handler will still respect log masks and attached observers. +The public Log API has grown a flush() method. This allows buffered log output to be explicitly flushed. At this time, the flush() method is only implemented by the console, file and mail handlers. + New unit tests for the Factory and Singleton construction methods have been added. EOT; Index: pear/Log/Log/composite.php diff -u pear/Log/Log/composite.php:1.19 pear/Log/Log/composite.php:1.20 --- pear/Log/Log/composite.php:1.19 Sat Nov 8 17:39:55 2003 +++ pear/Log/Log/composite.php Thu Jan 1 20:45:31 2004 @@ -1,9 +1,9 @@ <?php /** - * $Header: /repository/pear/Log/Log/composite.php,v 1.19 2003/11/08 22:39:55 jon Exp $ + * $Header: /repository/pear/Log/Log/composite.php,v 1.20 2004/01/02 01:45:31 jon Exp $ * $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $ * - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * @package Log */ @@ -74,6 +74,21 @@ } /** + * Flushes all open child instances. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + if ($this->_opened) { + foreach ($this->_children as $id => $child) { + $this->_children[$id]->flush(); + } + } + } + + /** * Sends $message and $priority to each child of this composite. * * @param mixed $message String or object containing the message Index: pear/Log/Log/console.php diff -u pear/Log/Log/console.php:1.16 pear/Log/Log/console.php:1.17 --- pear/Log/Log/console.php:1.16 Sat Nov 8 17:39:55 2003 +++ pear/Log/Log/console.php Thu Jan 1 20:45:31 2004 @@ -1,8 +1,8 @@ <?php /** - * $Header: /repository/pear/Log/Log/console.php,v 1.16 2003/11/08 22:39:55 jon Exp $ + * $Header: /repository/pear/Log/Log/console.php,v 1.17 2004/01/02 01:45:31 jon Exp $ * - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ * @package Log */ @@ -113,6 +113,17 @@ */ function _Log_console() { + $this->flush(); + } + + /** + * Flushes all pending ("buffered") data to the output stream. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { /* * If output buffering is enabled, dump the contents of the buffer to * the output stream. @@ -121,6 +132,8 @@ fwrite($this->_stream, $this->_buffer); $this->_buffer = ''; } + + return fflush($this->_stream); } /** Index: pear/Log/Log/file.php diff -u pear/Log/Log/file.php:1.34 pear/Log/Log/file.php:1.35 --- pear/Log/Log/file.php:1.34 Sat Nov 8 17:39:55 2003 +++ pear/Log/Log/file.php Thu Jan 1 20:45:31 2004 @@ -1,8 +1,8 @@ <?php /** - * $Header: /repository/pear/Log/Log/file.php,v 1.34 2003/11/08 22:39:55 jon Exp $ + * $Header: /repository/pear/Log/Log/file.php,v 1.35 2004/01/02 01:45:31 jon Exp $ * - * @version $Revision: 1.34 $ + * @version $Revision: 1.35 $ * @package Log */ @@ -224,6 +224,17 @@ } /** + * Flushes all pending data to the file handle. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + return fflush($this->_fp); + } + + /** * Logs $message to the output window. The message is also passed along * to any Log_observer instances that are observing this Log. * Index: pear/Log/Log/mail.php diff -u pear/Log/Log/mail.php:1.17 pear/Log/Log/mail.php:1.18 --- pear/Log/Log/mail.php:1.17 Thu Jan 1 20:26:59 2004 +++ pear/Log/Log/mail.php Thu Jan 1 20:45:31 2004 @@ -1,8 +1,8 @@ <?php /** - * $Header: /repository/pear/Log/Log/mail.php,v 1.17 2004/01/02 01:26:59 jon Exp $ + * $Header: /repository/pear/Log/Log/mail.php,v 1.18 2004/01/02 01:45:31 jon Exp $ * - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ * @package Log */ @@ -155,6 +155,23 @@ } /** + * Flushes the log output by forcing the email message to be sent now. + * Events that are logged after flush() is called will be appended to a + * new email message. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + /* + * It's sufficient to simply call close() to flush the output. + * The next call to log() will cause the handler to be reopened. + */ + return $this->close(); + } + + /** * Writes $message to the currently open mail message. * Calls open(), if necessary. * Index: pear/Log/docs/guide.txt diff -u pear/Log/docs/guide.txt:1.5 pear/Log/docs/guide.txt:1.6 --- pear/Log/docs/guide.txt:1.5 Mon Dec 29 02:13:34 2003 +++ pear/Log/docs/guide.txt Thu Jan 1 20:45:32 2004 @@ -8,8 +8,8 @@ :Author: Jon Parise :Contact: jon@php.net -:Date: $Date: 2003/12/29 07:13:34 $ -:Revision: $Revision: 1.5 $ +:Date: $Date: 2004/01/02 01:45:32 $ +:Revision: $Revision: 1.6 $ .. contents:: Contents .. section-numbering:: @@ -236,6 +236,38 @@ $logger->setMask($mask); +Flushing Log Events +------------------- +Some log handlers (such as `the console handler`_) support explicit +"buffering". When buffering is enabled, log events won't actually be written +to the output stream until the handler is closed. Other handlers (such as +`the file handler`_) support implicit buffering because they use the operating +system's IO routines, which may buffer the output. + +It's possible to force these handlers to flush their output, however, by +calling their ``flush()`` method:: + + $conf = array('buffering' => true); + $logger = &Log::singleton('console', '', 'test', $conf); + + for ($i = 0; $i < 10; $i++) { + $logger->log('This event will be buffered.'); + } + + /* Flush all of the buffered log events. */ + $logger->flush(); + + for ($i = 0; $i < 10; $i++) { + $logger->log('This event will be buffered.'); + } + + /* Implicitly flush the buffered events on close. */ + $logger->close(); + +At this time, the ``flush()`` method is only implemented by `the console +handler`_, `the file handler`_ and `the mail handler`_. + + Standard Log Handlers ===================== Index: pear/Log/tests/console.phpt diff -u pear/Log/tests/console.phpt:1.1 pear/Log/tests/console.phpt:1.2 --- pear/Log/tests/console.phpt:1.1 Sat Nov 15 21:40:17 2003 +++ pear/Log/tests/console.phpt Thu Jan 1 20:45:32 2004 @@ -11,7 +11,31 @@ $logger->log("Log entry $i"); } +echo "\n[Buffering / Flush Test]\n"; +$conf = array('lineFormat' => '%2$s [%3$s] %4$s', 'buffering' => true); +$buffered_logger = &Log::singleton('console', '', 'buffered', $conf); +for ($i = 0; $i < 3; $i++) { + $buffered_logger->log("Buffered log entry $i"); +} +echo "Pre-flush\n"; +$buffered_logger->flush(); +echo "Post-flush\n"; +for ($i = 0; $i < 3; $i++) { + $buffered_logger->log("Buffered log entry $i"); +} +$buffered_logger->close(); + --EXPECT-- ident [info] Log entry 0 ident [info] Log entry 1 ident [info] Log entry 2 + +[Buffering / Flush Test] +Pre-flush +buffered [info] Buffered log entry 0 +buffered [info] Buffered log entry 1 +buffered [info] Buffered log entry 2 +Post-flush +buffered [info] Buffered log entry 0 +buffered [info] Buffered log entry 1 +buffered [info] Buffered log entry 2
Index: pear/Log/Log.php diff -u pear/Log/Log.php:1.41 pear/Log/Log.php:1.42 --- pear/Log/Log.php:1.41 Sat Nov 8 17:39:54 2003 +++ pear/Log/Log.php Thu Jan 1 20:45:30 2004 @@ -1,9 +1,9 @@ <?php /** - * $Header: /repository/pear/Log/Log.php,v 1.41 2003/11/08 22:39:54 jon Exp $ + * $Header: /repository/pear/Log/Log.php,v 1.42 2004/01/02 01:45:30 jon Exp $ * $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $ * - * @version $Revision: 1.41 $ + * @version $Revision: 1.42 $ * @package Log */ @@ -194,6 +194,15 @@ } /** + * Abstract implementation of the flush() method. + * @since Log 1.8.2 + */ + function flush() + { + return false; + } + + /** * Abstract implementation of the log() method. * @since Log 1.0 */ Index: pear/Log/package.php diff -u pear/Log/package.php:1.5 pear/Log/package.php:1.6 --- pear/Log/package.php:1.5 Mon Dec 29 02:27:16 2003 +++ pear/Log/package.php Thu Jan 1 20:45:30 2004 @@ -6,11 +6,14 @@ $version = '1.8.2'; $notes = <<<EOT Added a new 'null' log handler. +Added a flush() method to the public Log API. EOT; $changelog = <<<EOT A new 'null' log handler that simply consumes log events has been added. The 'null' handler will still respect log masks and attached observers. +The public Log API has grown a flush() method. This allows buffered log output to be explicitly flushed. At this time, the flush() method is only implemented by the console, file and mail handlers. + New unit tests for the Factory and Singleton construction methods have been added. EOT; Index: pear/Log/Log/composite.php diff -u pear/Log/Log/composite.php:1.19 pear/Log/Log/composite.php:1.20 --- pear/Log/Log/composite.php:1.19 Sat Nov 8 17:39:55 2003 +++ pear/Log/Log/composite.php Thu Jan 1 20:45:31 2004 @@ -1,9 +1,9 @@ <?php /** - * $Header: /repository/pear/Log/Log/composite.php,v 1.19 2003/11/08 22:39:55 jon Exp $ + * $Header: /repository/pear/Log/Log/composite.php,v 1.20 2004/01/02 01:45:31 jon Exp $ * $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $ * - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * @package Log */ @@ -74,6 +74,21 @@ } /** + * Flushes all open child instances. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + if ($this->_opened) { + foreach ($this->_children as $id => $child) { + $this->_children[$id]->flush(); + } + } + } + + /** * Sends $message and $priority to each child of this composite. * * @param mixed $message String or object containing the message Index: pear/Log/Log/console.php diff -u pear/Log/Log/console.php:1.16 pear/Log/Log/console.php:1.17 --- pear/Log/Log/console.php:1.16 Sat Nov 8 17:39:55 2003 +++ pear/Log/Log/console.php Thu Jan 1 20:45:31 2004 @@ -1,8 +1,8 @@ <?php /** - * $Header: /repository/pear/Log/Log/console.php,v 1.16 2003/11/08 22:39:55 jon Exp $ + * $Header: /repository/pear/Log/Log/console.php,v 1.17 2004/01/02 01:45:31 jon Exp $ * - * @version $Revision: 1.16 $ + * @version $Revision: 1.17 $ * @package Log */ @@ -113,6 +113,17 @@ */ function _Log_console() { + $this->flush(); + } + + /** + * Flushes all pending ("buffered") data to the output stream. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { /* * If output buffering is enabled, dump the contents of the buffer to * the output stream. @@ -121,6 +132,8 @@ fwrite($this->_stream, $this->_buffer); $this->_buffer = ''; } + + return fflush($this->_stream); } /** Index: pear/Log/Log/file.php diff -u pear/Log/Log/file.php:1.34 pear/Log/Log/file.php:1.35 --- pear/Log/Log/file.php:1.34 Sat Nov 8 17:39:55 2003 +++ pear/Log/Log/file.php Thu Jan 1 20:45:31 2004 @@ -1,8 +1,8 @@ <?php /** - * $Header: /repository/pear/Log/Log/file.php,v 1.34 2003/11/08 22:39:55 jon Exp $ + * $Header: /repository/pear/Log/Log/file.php,v 1.35 2004/01/02 01:45:31 jon Exp $ * - * @version $Revision: 1.34 $ + * @version $Revision: 1.35 $ * @package Log */ @@ -224,6 +224,17 @@ } /** + * Flushes all pending data to the file handle. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + return fflush($this->_fp); + } + + /** * Logs $message to the output window. The message is also passed along * to any Log_observer instances that are observing this Log. * Index: pear/Log/Log/mail.php diff -u pear/Log/Log/mail.php:1.17 pear/Log/Log/mail.php:1.18 --- pear/Log/Log/mail.php:1.17 Thu Jan 1 20:26:59 2004 +++ pear/Log/Log/mail.php Thu Jan 1 20:45:31 2004 @@ -1,8 +1,8 @@ <?php /** - * $Header: /repository/pear/Log/Log/mail.php,v 1.17 2004/01/02 01:26:59 jon Exp $ + * $Header: /repository/pear/Log/Log/mail.php,v 1.18 2004/01/02 01:45:31 jon Exp $ * - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ * @package Log */ @@ -155,6 +155,23 @@ } /** + * Flushes the log output by forcing the email message to be sent now. + * Events that are logged after flush() is called will be appended to a + * new email message. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + /* + * It's sufficient to simply call close() to flush the output. + * The next call to log() will cause the handler to be reopened. + */ + return $this->close(); + } + + /** * Writes $message to the currently open mail message. * Calls open(), if necessary. * Index: pear/Log/docs/guide.txt diff -u pear/Log/docs/guide.txt:1.5 pear/Log/docs/guide.txt:1.6 --- pear/Log/docs/guide.txt:1.5 Mon Dec 29 02:13:34 2003 +++ pear/Log/docs/guide.txt Thu Jan 1 20:45:32 2004 @@ -8,8 +8,8 @@ :Author: Jon Parise :Contact: jon@php.net -:Date: $Date: 2003/12/29 07:13:34 $ -:Revision: $Revision: 1.5 $ +:Date: $Date: 2004/01/02 01:45:32 $ +:Revision: $Revision: 1.6 $ .. contents:: Contents .. section-numbering:: @@ -236,6 +236,38 @@ $logger->setMask($mask); +Flushing Log Events +------------------- +Some log handlers (such as `the console handler`_) support explicit +"buffering". When buffering is enabled, log events won't actually be written +to the output stream until the handler is closed. Other handlers (such as +`the file handler`_) support implicit buffering because they use the operating +system's IO routines, which may buffer the output. + +It's possible to force these handlers to flush their output, however, by +calling their ``flush()`` method:: + + $conf = array('buffering' => true); + $logger = &Log::singleton('console', '', 'test', $conf); + + for ($i = 0; $i < 10; $i++) { + $logger->log('This event will be buffered.'); + } + + /* Flush all of the buffered log events. */ + $logger->flush(); + + for ($i = 0; $i < 10; $i++) { + $logger->log('This event will be buffered.'); + } + + /* Implicitly flush the buffered events on close. */ + $logger->close(); + +At this time, the ``flush()`` method is only implemented by `the console +handler`_, `the file handler`_ and `the mail handler`_. + + Standard Log Handlers ===================== Index: pear/Log/tests/console.phpt diff -u pear/Log/tests/console.phpt:1.1 pear/Log/tests/console.phpt:1.2 --- pear/Log/tests/console.phpt:1.1 Sat Nov 15 21:40:17 2003 +++ pear/Log/tests/console.phpt Thu Jan 1 20:45:32 2004 @@ -11,7 +11,31 @@ $logger->log("Log entry $i"); } +echo "\n[Buffering / Flush Test]\n"; +$conf = array('lineFormat' => '%2$s [%3$s] %4$s', 'buffering' => true); +$buffered_logger = &Log::singleton('console', '', 'buffered', $conf); +for ($i = 0; $i < 3; $i++) { + $buffered_logger->log("Buffered log entry $i"); +} +echo "Pre-flush\n"; +$buffered_logger->flush(); +echo "Post-flush\n"; +for ($i = 0; $i < 3; $i++) { + $buffered_logger->log("Buffered log entry $i"); +} +$buffered_logger->close(); + --EXPECT-- ident [info] Log entry 0 ident [info] Log entry 1 ident [info] Log entry 2 + +[Buffering / Flush Test] +Pre-flush +buffered [info] Buffered log entry 0 +buffered [info] Buffered log entry 1 +buffered [info] Buffered log entry 2 +Post-flush +buffered [info] Buffered log entry 0 +buffered [info] Buffered log entry 1 +buffered [info] Buffered log entry 2