home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Log / error_log.php < prev    next >
Encoding:
PHP Script  |  2008-07-02  |  3.4 KB  |  128 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log/error_log.php,v 1.8 2006/06/29 07:09:21 jon Exp $
  4.  *
  5.  * @version $Revision: 1.8 $
  6.  * @package Log
  7.  */
  8.  
  9. /**
  10.  * The Log_error_log class is a concrete implementation of the Log abstract
  11.  * class that logs messages using PHP's error_log() function.
  12.  *
  13.  * @author  Jon Parise <jon@php.net>
  14.  * @since   Log 1.7.0
  15.  * @package Log
  16.  *
  17.  * @example error_log.php   Using the error_log handler.
  18.  */
  19. class Log_error_log extends Log
  20. {
  21.     /**
  22.      * The error_log() log type.
  23.      * @var integer
  24.      * @access private
  25.      */
  26.     var $_type = PEAR_LOG_TYPE_SYSTEM;
  27.  
  28.     /**
  29.      * The type-specific destination value.
  30.      * @var string
  31.      * @access private
  32.      */
  33.     var $_destination = '';
  34.  
  35.     /**
  36.      * Additional headers to pass to the mail() function when the
  37.      * PEAR_LOG_TYPE_MAIL type is used.
  38.      * @var string
  39.      * @access private
  40.      */
  41.     var $_extra_headers = '';
  42.  
  43.     /**
  44.      * Constructs a new Log_error_log object.
  45.      *
  46.      * @param string $name     Ignored.
  47.      * @param string $ident    The identity string.
  48.      * @param array  $conf     The configuration array.
  49.      * @param int    $level    Log messages up to and including this level.
  50.      * @access public
  51.      */
  52.     function Log_error_log($name, $ident = '', $conf = array(),
  53.                            $level = PEAR_LOG_DEBUG)
  54.     {
  55.         $this->_id = md5(microtime());
  56.         $this->_type = $name;
  57.         $this->_ident = $ident;
  58.         $this->_mask = Log::UPTO($level);
  59.  
  60.         if (!empty($conf['destination'])) {
  61.             $this->_destination = $conf['destination'];
  62.         }
  63.         if (!empty($conf['extra_headers'])) {
  64.             $this->_extra_headers = $conf['extra_headers'];
  65.         }
  66.     }
  67.  
  68.     /**
  69.      * Opens the handler.
  70.      *
  71.      * @access  public
  72.      * @since   Log 1.9.6
  73.      */
  74.     function open()
  75.     {
  76.         $this->_opened = true;
  77.         return true;
  78.     }
  79.  
  80.     /**
  81.      * Closes the handler.
  82.      *
  83.      * @access  public
  84.      * @since   Log 1.9.6
  85.      */
  86.     function close()
  87.     {
  88.         $this->_opened = false;
  89.         return true;
  90.     }
  91.  
  92.     /**
  93.      * Logs $message using PHP's error_log() function.  The message is also
  94.      * passed along to any Log_observer instances that are observing this Log.
  95.      *
  96.      * @param mixed  $message   String or object containing the message to log.
  97.      * @param string $priority The priority of the message.  Valid
  98.      *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  99.      *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  100.      *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  101.      * @return boolean  True on success or false on failure.
  102.      * @access public
  103.      */
  104.     function log($message, $priority = null)
  105.     {
  106.         /* If a priority hasn't been specified, use the default value. */
  107.         if ($priority === null) {
  108.             $priority = $this->_priority;
  109.         }
  110.  
  111.         /* Abort early if the priority is above the maximum logging level. */
  112.         if (!$this->_isMasked($priority)) {
  113.             return false;
  114.         }
  115.  
  116.         /* Extract the string representation of the message. */
  117.         $message = $this->_extractMessage($message);
  118.  
  119.         $success = error_log($this->_ident . ': ' . $message, $this->_type,
  120.                              $this->_destination, $this->_extra_headers);
  121.  
  122.         $this->_announce(array('priority' => $priority, 'message' => $message));
  123.  
  124.         return $success;
  125.     }
  126.  
  127. }
  128.