cvs: pear /Log Log.php /Log/Log syslog.php

From: Date: Wed, 24 Jul 2002 06:00:39 +0000
Subject: cvs: pear /Log Log.php /Log/Log syslog.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-5314@lists.php.net to get a copy of this message
jon Wed Jul 24 02:00:39 2002 EDT Modified files: /pear/Log Log.php /pear/Log/Log syslog.php Log: Because Windows does not define unique values for the syslog LOG_* values, we define our own set of PEAR_LOG_* constants. We map these PEAR_LOG_* constants to the appropriate LOG_* value at the syslog level when required. Index: pear/Log/Log.php diff -u pear/Log/Log.php:1.8 pear/Log/Log.php:1.9 --- pear/Log/Log.php:1.8 Mon Apr 29 01:18:45 2002 +++ pear/Log/Log.php Wed Jul 24 02:00:35 2002 @@ -1,14 +1,23 @@ <?php -// $Id: Log.php,v 1.8 2002/04/29 05:18:45 jon Exp $ +// $Id: Log.php,v 1.9 2002/07/24 06:00:35 jon Exp $ // $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $ +define('PEAR_LOG_EMERG', 0); +define('PEAR_LOG_ALERT', 1); +define('PEAR_LOG_CRIT', 2); +define('PEAR_LOG_ERR', 3); +define('PEAR_LOG_WARNING', 4); +define('PEAR_LOG_NOTICE', 5); +define('PEAR_LOG_INFO', 6); +define('PEAR_LOG_DEBUG', 7); + /** * The Log:: class implements both an abstraction for various logging * mechanisms and the Subject end of a Subject-Observer pattern. * * @author Chuck Hagenbuch <chuck@horde.org> * @author Jon Parise <jon@horde.org> - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * @since Horde 1.3 * @package Log */ @@ -36,7 +45,7 @@ * @var int * @access private */ - var $_maxLevel = LOG_DEBUG; + var $_maxLevel = PEAR_LOG_DEBUG; /** * Holds all Log_observer objects that wish to be notified of new messages. @@ -72,7 +81,7 @@ * @access public */ function factory($type, $name = '', $ident = '', $conf = array(), - $maxLevel = LOG_DEBUG) + $maxLevel = PEAR_LOG_DEBUG) { $type = strtolower($type); $classfile = 'Log/' . $type . '.php'; @@ -120,7 +129,7 @@ * @access public */ function &singleton($type, $name = '', $ident = '', $conf = array(), - $maxLevel = LOG_DEBUG) + $maxLevel = PEAR_LOG_DEBUG) { static $instances; if (!isset($instances)) $instances = array(); @@ -135,23 +144,23 @@ } /** - * Returns the string representation of a LOG_* integer constant. + * Returns the string representation of a PEAR_LOG_* integer constant. * - * @param int $priority A LOG_* integer constant. + * @param int $priority A PEAR_LOG_* integer constant. * * @return string The string representation of $priority. */ function priorityToString($priority) { $priorities = array( - LOG_EMERG => 'emergency', - LOG_ALERT => 'alert', - LOG_CRIT => 'critical', - LOG_ERR => 'error', - LOG_WARNING => 'warning', - LOG_NOTICE => 'notice', - LOG_INFO => 'info', - LOG_DEBUG => 'debug' + PEAR_LOG_EMERG => 'emergency', + PEAR_LOG_ALERT => 'alert', + PEAR_LOG_CRIT => 'critical', + PEAR_LOG_ERR => 'error', + PEAR_LOG_WARNING => 'warning', + PEAR_LOG_NOTICE => 'notice', + PEAR_LOG_INFO => 'info', + PEAR_LOG_DEBUG => 'debug' ); return $priorities[$priority]; Index: pear/Log/Log/syslog.php diff -u pear/Log/Log/syslog.php:1.4 pear/Log/Log/syslog.php:1.5 --- pear/Log/Log/syslog.php:1.4 Mon Apr 29 01:18:45 2002 +++ pear/Log/Log/syslog.php Wed Jul 24 02:00:37 2002 @@ -1,5 +1,5 @@ <?php -// $Id: syslog.php,v 1.4 2002/04/29 05:18:45 jon Exp $ +// $Id: syslog.php,v 1.5 2002/07/24 06:00:37 jon Exp $ // $Horde: horde/lib/Log/syslog.php,v 1.6 2000/06/28 21:36:13 jon Exp $ /** @@ -8,7 +8,7 @@ * (PHP emulates this with the Event Log on Windows machines). * * @author Chuck Hagenbuch <chuck@horde.org> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @since Horde 1.3 * @package Log */ @@ -68,12 +68,12 @@ } /** - * Sends $message to the currently open syslog * connection. Calls + * Sends $message to the currently open syslog connection. Calls * open() if necessary. Also passes the message along to any Log_observer * instances that are observing this Log. * * @param string $message The textual message to be logged. - * @param string $priority (optional) The priority of the message. Valid + * @param int $priority (optional) The priority of the message. Valid * values are: LOG_EMERG, LOG_ALERT, LOG_CRIT, * LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, * and LOG_DEBUG. The default is LOG_INFO. @@ -88,9 +88,39 @@ $this->open(); } - syslog($priority, $message); + syslog($this->_toSyslog($priority), $message); $this->notifyAll(array('priority' => $priority, 'message' => $message)); } -} + /** + * Converts a PEAR_LOG_* constant into a syslog LOG_* constant. + * + * This function exists because, under Windows, not all of the LOG_* + * constants have unique values. Instead, the PEAR_LOG_* were introduced + * for global use, with the conversion to the LOG_* constants kept local to + * to the syslog driver. + * + * @param int $priority PEAR_LOG_* value to convert to LOG_* value. + * + * @return The LOG_* representation of $priority. + * + * @access private + */ + function _toSyslog($priority) + { + static $priorities = array( + PEAR_LOG_EMERG => LOG_EMERG, + PEAR_LOG_ALERT => LOG_ALERT, + PEAR_LOG_CRIT => LOG_CRIT, + PEAR_LOG_ERR => LOG_ERR, + PEAR_LOG_WARNING => LOG_WARNING, + PEAR_LOG_NOTICE => LOG_NOTICE, + PEAR_LOG_INFO => LOG_INFO, + PEAR_LOG_DEBUG => LOG_DEBUG + ); + + return $priorities[$priority]; + } + +} ?>

« previous php.pear.cvs (#5314) next »