home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Developers / XAMPP 1.5.4 / Windows installer / xampp-win32-1.5.4-installer.exe / xampp / php / pear / Log / display.php < prev    next >
Encoding:
PHP Script  |  2006-04-07  |  3.5 KB  |  118 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/display.php,v 1.8 2005/08/06 23:28:35 jon Exp $
  4.  *
  5.  * @version $Revision: 1.8 $
  6.  * @package Log
  7.  */
  8.  
  9. /**
  10.  * The Log_display class is a concrete implementation of the Log::
  11.  * abstract class which writes message into browser in usual PHP maner.
  12.  * This may be useful because when you use PEAR::setErrorHandling in
  13.  * PEAR_ERROR_CALLBACK mode error messages are not displayed by
  14.  * PHP error handler.
  15.  *
  16.  * @author  Paul Yanchenko <pusher@inaco.ru>
  17.  * @since   Log 1.8.0
  18.  * @package Log
  19.  *
  20.  * @example display.php     Using the display handler.
  21.  */
  22. class Log_display extends Log
  23. {
  24.     /**
  25.      * String to output before an error message
  26.      * @var string
  27.      * @access private
  28.      */
  29.     var $_error_prepend = '';
  30.  
  31.     /**
  32.      * String to output after an error message
  33.      * @var string
  34.      * @access private
  35.      */
  36.     var $_error_append = '';
  37.  
  38.     /**
  39.      * String used to represent a line break.
  40.      * @var string
  41.      * @access private
  42.      */
  43.     var $_linebreak = "<br />\n";
  44.  
  45.     /**
  46.      * Constructs a new Log_display object.
  47.      *
  48.      * @param string $name     Ignored.
  49.      * @param string $ident    The identity string.
  50.      * @param array  $conf     The configuration array.
  51.      * @param int    $level    Log messages up to and including this level.
  52.      * @access public
  53.      */
  54.     function Log_display($name = '', $ident = '', $conf = array(),
  55.                          $level = PEAR_LOG_DEBUG)
  56.     {
  57.         $this->_id = md5(microtime());
  58.         $this->_ident = $ident;
  59.         $this->_mask = Log::UPTO($level);
  60.  
  61.         if (isset($conf['error_prepend'])) {
  62.             $this->_error_prepend = $conf['error_prepend'];
  63.         } else {
  64.             $this->_error_prepend = ini_get('error_prepend_string');
  65.         }
  66.  
  67.         if (isset($conf['error_append'])) {
  68.             $this->_error_append = $conf['error_append'];
  69.         } else {
  70.             $this->_error_append = ini_get('error_append_string');
  71.         }
  72.  
  73.         if (isset($conf['linebreak'])) {
  74.             $this->_linebreak = $conf['linebreak'];
  75.         }
  76.     }
  77.  
  78.     /**
  79.      * Writes $message to the text browser. Also, passes the message
  80.      * along to any Log_observer instances that are observing this Log.
  81.      *
  82.      * @param mixed  $message    String or object containing the message to log.
  83.      * @param string $priority The priority of the message.  Valid
  84.      *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  85.      *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  86.      *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  87.      * @return boolean  True on success or false on failure.
  88.      * @access public
  89.      */
  90.     function log($message, $priority = null)
  91.     {
  92.         /* If a priority hasn't been specified, use the default value. */
  93.         if ($priority === null) {
  94.             $priority = $this->_priority;
  95.         }
  96.  
  97.         /* Abort early if the priority is above the maximum logging level. */
  98.         if (!$this->_isMasked($priority)) {
  99.             return false;
  100.         }
  101.  
  102.         /* Extract the string representation of the message. */
  103.         $message = $this->_extractMessage($message);
  104.  
  105.         /* Build and output the complete log line. */
  106.         echo $this->_error_prepend .
  107.              '<b>' . ucfirst($this->priorityToString($priority)) . '</b>: '.
  108.              nl2br(htmlspecialchars($message)) .
  109.              $this->_error_append . $this->_linebreak;
  110.  
  111.         /* Notify observers about this log message. */
  112.         $this->_announce(array('priority' => $priority, 'message' => $message));
  113.  
  114.         return true;
  115.     }
  116.  
  117. }
  118.