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.php < prev    next >
PHP Script  |  2008-07-02  |  26KB  |  848 lines

  1. <?php
  2. /**
  3.  * $Header: /repository/pear/Log/Log.php,v 1.69 2008/01/19 22:20:55 jon Exp $
  4.  * $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $
  5.  *
  6.  * @version $Revision: 1.69 $
  7.  * @package Log
  8.  */
  9.  
  10. define('PEAR_LOG_EMERG',    0);     /* System is unusable */
  11. define('PEAR_LOG_ALERT',    1);     /* Immediate action required */
  12. define('PEAR_LOG_CRIT',     2);     /* Critical conditions */
  13. define('PEAR_LOG_ERR',      3);     /* Error conditions */
  14. define('PEAR_LOG_WARNING',  4);     /* Warning conditions */
  15. define('PEAR_LOG_NOTICE',   5);     /* Normal but significant */
  16. define('PEAR_LOG_INFO',     6);     /* Informational */
  17. define('PEAR_LOG_DEBUG',    7);     /* Debug-level messages */
  18.  
  19. define('PEAR_LOG_ALL',      0xffffffff);    /* All messages */
  20. define('PEAR_LOG_NONE',     0x00000000);    /* No message */
  21.  
  22. /* Log types for PHP's native error_log() function. */
  23. define('PEAR_LOG_TYPE_SYSTEM',  0); /* Use PHP's system logger */
  24. define('PEAR_LOG_TYPE_MAIL',    1); /* Use PHP's mail() function */
  25. define('PEAR_LOG_TYPE_DEBUG',   2); /* Use PHP's debugging connection */
  26. define('PEAR_LOG_TYPE_FILE',    3); /* Append to a file */
  27.  
  28. /**
  29.  * The Log:: class implements both an abstraction for various logging
  30.  * mechanisms and the Subject end of a Subject-Observer pattern.
  31.  *
  32.  * @author  Chuck Hagenbuch <chuck@horde.org>
  33.  * @author  Jon Parise <jon@php.net>
  34.  * @since   Horde 1.3
  35.  * @package Log
  36.  */
  37. class Log
  38. {
  39.     /**
  40.      * Indicates whether or not the log can been opened / connected.
  41.      *
  42.      * @var boolean
  43.      * @access protected
  44.      */
  45.     var $_opened = false;
  46.  
  47.     /**
  48.      * Instance-specific unique identification number.
  49.      *
  50.      * @var integer
  51.      * @access protected
  52.      */
  53.     var $_id = 0;
  54.  
  55.     /**
  56.      * The label that uniquely identifies this set of log messages.
  57.      *
  58.      * @var string
  59.      * @access protected
  60.      */
  61.     var $_ident = '';
  62.  
  63.     /**
  64.      * The default priority to use when logging an event.
  65.      *
  66.      * @var integer
  67.      * @access protected
  68.      */
  69.     var $_priority = PEAR_LOG_INFO;
  70.  
  71.     /**
  72.      * The bitmask of allowed log levels.
  73.      *
  74.      * @var integer
  75.      * @access protected
  76.      */
  77.     var $_mask = PEAR_LOG_ALL;
  78.  
  79.     /**
  80.      * Holds all Log_observer objects that wish to be notified of new messages.
  81.      *
  82.      * @var array
  83.      * @access protected
  84.      */
  85.     var $_listeners = array();
  86.  
  87.     /**
  88.      * Maps canonical format keys to position arguments for use in building
  89.      * "line format" strings.
  90.      *
  91.      * @var array
  92.      * @access protected
  93.      */
  94.     var $_formatMap = array('%{timestamp}'  => '%1$s',
  95.                             '%{ident}'      => '%2$s',
  96.                             '%{priority}'   => '%3$s',
  97.                             '%{message}'    => '%4$s',
  98.                             '%{file}'       => '%5$s',
  99.                             '%{line}'       => '%6$s',
  100.                             '%{function}'   => '%7$s',
  101.                             '%\{'           => '%%{');
  102.  
  103.     /**
  104.      * Utility function which wraps PHP's class_exists() function to ensure
  105.      * consistent behavior between PHP versions 4 and 5.  Autoloading behavior
  106.      * is always disabled.
  107.      *
  108.      * @param string $class     The name of the class whose existence should
  109.      *                          be tested.
  110.      *
  111.      * @return bool             True if the class exists.
  112.      *
  113.      * @access private
  114.      * @since Log 1.9.13
  115.      */
  116.     function _classExists($class)
  117.     {
  118.         if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
  119.             return class_exists($class, false);
  120.         }
  121.  
  122.         return class_exists($class);
  123.     }
  124.  
  125.     /**
  126.      * Attempts to return a concrete Log instance of type $handler.
  127.      *
  128.      * @param string $handler   The type of concrete Log subclass to return.
  129.      *                          Attempt to dynamically include the code for
  130.      *                          this subclass. Currently, valid values are
  131.      *                          'console', 'syslog', 'sql', 'file', and 'mcal'.
  132.      *
  133.      * @param string $name      The name of the actually log file, table, or
  134.      *                          other specific store to use. Defaults to an
  135.      *                          empty string, with which the subclass will
  136.      *                          attempt to do something intelligent.
  137.      *
  138.      * @param string $ident     The identity reported to the log system.
  139.      *
  140.      * @param array  $conf      A hash containing any additional configuration
  141.      *                          information that a subclass might need.
  142.      *
  143.      * @param int $level        Log messages up to and including this level.
  144.      *
  145.      * @return object Log       The newly created concrete Log instance, or
  146.      *                          null on an error.
  147.      * @access public
  148.      * @since Log 1.0
  149.      */
  150.     function &factory($handler, $name = '', $ident = '', $conf = array(),
  151.                       $level = PEAR_LOG_DEBUG)
  152.     {
  153.         $handler = strtolower($handler);
  154.         $class = 'Log_' . $handler;
  155.         $classfile = 'Log/' . $handler . '.php';
  156.  
  157.         /*
  158.          * Attempt to include our version of the named class, but don't treat
  159.          * a failure as fatal.  The caller may have already included their own
  160.          * version of the named class.
  161.          */
  162.         if (!Log::_classExists($class)) {
  163.             include_once $classfile;
  164.         }
  165.  
  166.         /* If the class exists, return a new instance of it. */
  167.         if (Log::_classExists($class)) {
  168.             $obj = &new $class($name, $ident, $conf, $level);
  169.             return $obj;
  170.         }
  171.  
  172.         $null = null;
  173.         return $null;
  174.     }
  175.  
  176.     /**
  177.      * Attempts to return a reference to a concrete Log instance of type
  178.      * $handler, only creating a new instance if no log instance with the same
  179.      * parameters currently exists.
  180.      *
  181.      * You should use this if there are multiple places you might create a
  182.      * logger, you don't want to create multiple loggers, and you don't want to
  183.      * check for the existance of one each time. The singleton pattern does all
  184.      * the checking work for you.
  185.      *
  186.      * <b>You MUST call this method with the $var = &Log::singleton() syntax.
  187.      * Without the ampersand (&) in front of the method name, you will not get
  188.      * a reference, you will get a copy.</b>
  189.      *
  190.      * @param string $handler   The type of concrete Log subclass to return.
  191.      *                          Attempt to dynamically include the code for
  192.      *                          this subclass. Currently, valid values are
  193.      *                          'console', 'syslog', 'sql', 'file', and 'mcal'.
  194.      *
  195.      * @param string $name      The name of the actually log file, table, or
  196.      *                          other specific store to use.  Defaults to an
  197.      *                          empty string, with which the subclass will
  198.      *                          attempt to do something intelligent.
  199.      *
  200.      * @param string $ident     The identity reported to the log system.
  201.      *
  202.      * @param array $conf       A hash containing any additional configuration
  203.      *                          information that a subclass might need.
  204.      *
  205.      * @param int $level        Log messages up to and including this level.
  206.      *
  207.      * @return object Log       The newly created concrete Log instance, or
  208.      *                          null on an error.
  209.      * @access public
  210.      * @since Log 1.0
  211.      */
  212.     function &singleton($handler, $name = '', $ident = '', $conf = array(),
  213.                         $level = PEAR_LOG_DEBUG)
  214.     {
  215.         static $instances;
  216.         if (!isset($instances)) $instances = array();
  217.  
  218.         $signature = serialize(array($handler, $name, $ident, $conf, $level));
  219.         if (!isset($instances[$signature])) {
  220.             $instances[$signature] = &Log::factory($handler, $name, $ident,
  221.                                                    $conf, $level);
  222.         }
  223.  
  224.         return $instances[$signature];
  225.     }
  226.  
  227.     /**
  228.      * Abstract implementation of the open() method.
  229.      * @since Log 1.0
  230.      */
  231.     function open()
  232.     {
  233.         return false;
  234.     }
  235.  
  236.     /**
  237.      * Abstract implementation of the close() method.
  238.      * @since Log 1.0
  239.      */
  240.     function close()
  241.     {
  242.         return false;
  243.     }
  244.  
  245.     /**
  246.      * Abstract implementation of the flush() method.
  247.      * @since Log 1.8.2
  248.      */
  249.     function flush()
  250.     {
  251.         return false;
  252.     }
  253.  
  254.     /**
  255.      * Abstract implementation of the log() method.
  256.      * @since Log 1.0
  257.      */
  258.     function log($message, $priority = null)
  259.     {
  260.         return false;
  261.     }
  262.  
  263.     /**
  264.      * A convenience function for logging a emergency event.  It will log a
  265.      * message at the PEAR_LOG_EMERG log level.
  266.      *
  267.      * @param   mixed   $message    String or object containing the message
  268.      *                              to log.
  269.      *
  270.      * @return  boolean True if the message was successfully logged.
  271.      *
  272.      * @access  public
  273.      * @since   Log 1.7.0
  274.      */
  275.     function emerg($message)
  276.     {
  277.         return $this->log($message, PEAR_LOG_EMERG);
  278.     }
  279.  
  280.     /**
  281.      * A convenience function for logging an alert event.  It will log a
  282.      * message at the PEAR_LOG_ALERT log level.
  283.      *
  284.      * @param   mixed   $message    String or object containing the message
  285.      *                              to log.
  286.      *
  287.      * @return  boolean True if the message was successfully logged.
  288.      *
  289.      * @access  public
  290.      * @since   Log 1.7.0
  291.      */
  292.     function alert($message)
  293.     {
  294.         return $this->log($message, PEAR_LOG_ALERT);
  295.     }
  296.  
  297.     /**
  298.      * A convenience function for logging a critical event.  It will log a
  299.      * message at the PEAR_LOG_CRIT log level.
  300.      *
  301.      * @param   mixed   $message    String or object containing the message
  302.      *                              to log.
  303.      *
  304.      * @return  boolean True if the message was successfully logged.
  305.      *
  306.      * @access  public
  307.      * @since   Log 1.7.0
  308.      */
  309.     function crit($message)
  310.     {
  311.         return $this->log($message, PEAR_LOG_CRIT);
  312.     }
  313.  
  314.     /**
  315.      * A convenience function for logging a error event.  It will log a
  316.      * message at the PEAR_LOG_ERR log level.
  317.      *
  318.      * @param   mixed   $message    String or object containing the message
  319.      *                              to log.
  320.      *
  321.      * @return  boolean True if the message was successfully logged.
  322.      *
  323.      * @access  public
  324.      * @since   Log 1.7.0
  325.      */
  326.     function err($message)
  327.     {
  328.         return $this->log($message, PEAR_LOG_ERR);
  329.     }
  330.  
  331.     /**
  332.      * A convenience function for logging a warning event.  It will log a
  333.      * message at the PEAR_LOG_WARNING log level.
  334.      *
  335.      * @param   mixed   $message    String or object containing the message
  336.      *                              to log.
  337.      *
  338.      * @return  boolean True if the message was successfully logged.
  339.      *
  340.      * @access  public
  341.      * @since   Log 1.7.0
  342.      */
  343.     function warning($message)
  344.     {
  345.         return $this->log($message, PEAR_LOG_WARNING);
  346.     }
  347.  
  348.     /**
  349.      * A convenience function for logging a notice event.  It will log a
  350.      * message at the PEAR_LOG_NOTICE log level.
  351.      *
  352.      * @param   mixed   $message    String or object containing the message
  353.      *                              to log.
  354.      *
  355.      * @return  boolean True if the message was successfully logged.
  356.      *
  357.      * @access  public
  358.      * @since   Log 1.7.0
  359.      */
  360.     function notice($message)
  361.     {
  362.         return $this->log($message, PEAR_LOG_NOTICE);
  363.     }
  364.  
  365.     /**
  366.      * A convenience function for logging a information event.  It will log a
  367.      * message at the PEAR_LOG_INFO log level.
  368.      *
  369.      * @param   mixed   $message    String or object containing the message
  370.      *                              to log.
  371.      *
  372.      * @return  boolean True if the message was successfully logged.
  373.      *
  374.      * @access  public
  375.      * @since   Log 1.7.0
  376.      */
  377.     function info($message)
  378.     {
  379.         return $this->log($message, PEAR_LOG_INFO);
  380.     }
  381.  
  382.     /**
  383.      * A convenience function for logging a debug event.  It will log a
  384.      * message at the PEAR_LOG_DEBUG log level.
  385.      *
  386.      * @param   mixed   $message    String or object containing the message
  387.      *                              to log.
  388.      *
  389.      * @return  boolean True if the message was successfully logged.
  390.      *
  391.      * @access  public
  392.      * @since   Log 1.7.0
  393.      */
  394.     function debug($message)
  395.     {
  396.         return $this->log($message, PEAR_LOG_DEBUG);
  397.     }
  398.  
  399.     /**
  400.      * Returns the string representation of the message data.
  401.      *
  402.      * If $message is an object, _extractMessage() will attempt to extract
  403.      * the message text using a known method (such as a PEAR_Error object's
  404.      * getMessage() method).  If a known method, cannot be found, the
  405.      * serialized representation of the object will be returned.
  406.      *
  407.      * If the message data is already a string, it will be returned unchanged.
  408.      *
  409.      * @param  mixed $message   The original message data.  This may be a
  410.      *                          string or any object.
  411.      *
  412.      * @return string           The string representation of the message.
  413.      *
  414.      * @access protected
  415.      */
  416.     function _extractMessage($message)
  417.     {
  418.         /*
  419.          * If we've been given an object, attempt to extract the message using
  420.          * a known method.  If we can't find such a method, default to the
  421.          * "human-readable" version of the object.
  422.          *
  423.          * We also use the human-readable format for arrays.
  424.          */
  425.         if (is_object($message)) {
  426.             if (method_exists($message, 'getmessage')) {
  427.                 $message = $message->getMessage();
  428.             } else if (method_exists($message, 'tostring')) {
  429.                 $message = $message->toString();
  430.             } else if (method_exists($message, '__tostring')) {
  431.                 if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
  432.                     $message = (string)$message;
  433.                 } else {
  434.                     $message = $message->__toString();
  435.                 }
  436.             } else {
  437.                 $message = print_r($message, true);
  438.             }
  439.         } else if (is_array($message)) {
  440.             if (isset($message['message'])) {
  441.                 $message = $message['message'];
  442.             } else {
  443.                 $message = print_r($message, true);
  444.             }
  445.         }
  446.  
  447.         /* Otherwise, we assume the message is a string. */
  448.         return $message;
  449.     }
  450.  
  451.     /**
  452.      * Using debug_backtrace(), returns the file, line, and enclosing function
  453.      * name of the source code context from which log() was invoked.
  454.      *
  455.      * @param   int     $depth  The initial number of frames we should step
  456.      *                          back into the trace.
  457.      *
  458.      * @return  array   Array containing three strings: the filename, the line,
  459.      *                  and the function name from which log() was called.
  460.      *
  461.      * @access  private
  462.      * @since   Log 1.9.4
  463.      */
  464.     function _getBacktraceVars($depth)
  465.     {
  466.         /* Start by generating a backtrace from the current call (here). */
  467.         $backtrace = debug_backtrace();
  468.  
  469.         /*
  470.          * If we were ultimately invoked by the composite handler, we need to
  471.          * increase our depth one additional level to compensate.
  472.          */
  473.         if (strcasecmp(@$backtrace[$depth+1]['class'], 'Log_composite') == 0) {
  474.             $depth++;
  475.         }
  476.  
  477.         /*
  478.          * We're interested in the frame which invoked the log() function, so
  479.          * we need to walk back some number of frames into the backtrace.  The
  480.          * $depth parameter tells us where to start looking.   We go one step
  481.          * further back to find the name of the encapsulating function from
  482.          * which log() was called.
  483.          */
  484.         $file = @$backtrace[$depth]['file'];
  485.         $line = @$backtrace[$depth]['line'];
  486.         $func = @$backtrace[$depth + 1]['function'];
  487.  
  488.         /*
  489.          * However, if log() was called from one of our "shortcut" functions,
  490.          * we're going to need to go back an additional step.
  491.          */
  492.         if (in_array($func, array('emerg', 'alert', 'crit', 'err', 'warning',
  493.                                   'notice', 'info', 'debug'))) {
  494.             $file = @$backtrace[$depth + 1]['file'];
  495.             $line = @$backtrace[$depth + 1]['line'];
  496.             $func = @$backtrace[$depth + 2]['function'];
  497.         }
  498.  
  499.         /*
  500.          * If we couldn't extract a function name (perhaps because we were
  501.          * executed from the "main" context), provide a default value.
  502.          */
  503.         if (is_null($func)) {
  504.             $func = '(none)';
  505.         }
  506.  
  507.         /* Return a 3-tuple containing (file, line, function). */
  508.         return array($file, $line, $func);
  509.     }
  510.  
  511.     /**
  512.      * Produces a formatted log line based on a format string and a set of
  513.      * variables representing the current log record and state.
  514.      *
  515.      * @return  string  Formatted log string.
  516.      *
  517.      * @access  protected
  518.      * @since   Log 1.9.4
  519.      */
  520.     function _format($format, $timestamp, $priority, $message)
  521.     {
  522.         /*
  523.          * If the format string references any of the backtrace-driven
  524.          * variables (%5, %6, %7), generate the backtrace and fetch them.
  525.          */
  526.         if (strpos($format, '%5') || strpos($format, '%6') || strpos($format, '%7')) {
  527.             list($file, $line, $func) = $this->_getBacktraceVars(2);
  528.         }
  529.  
  530.         /*
  531.          * Build the formatted string.  We use the sprintf() function's
  532.          * "argument swapping" capability to dynamically select and position
  533.          * the variables which will ultimately appear in the log string.
  534.          */
  535.         return sprintf($format,
  536.                        $timestamp,
  537.                        $this->_ident,
  538.                        $this->priorityToString($priority),
  539.                        $message,
  540.                        isset($file) ? $file : '',
  541.                        isset($line) ? $line : '',
  542.                        isset($func) ? $func : '');
  543.     }
  544.  
  545.     /**
  546.      * Returns the string representation of a PEAR_LOG_* integer constant.
  547.      *
  548.      * @param int $priority     A PEAR_LOG_* integer constant.
  549.      *
  550.      * @return string           The string representation of $level.
  551.      *
  552.      * @access  public
  553.      * @since   Log 1.0
  554.      */
  555.     function priorityToString($priority)
  556.     {
  557.         $levels = array(
  558.             PEAR_LOG_EMERG   => 'emergency',
  559.             PEAR_LOG_ALERT   => 'alert',
  560.             PEAR_LOG_CRIT    => 'critical',
  561.             PEAR_LOG_ERR     => 'error',
  562.             PEAR_LOG_WARNING => 'warning',
  563.             PEAR_LOG_NOTICE  => 'notice',
  564.             PEAR_LOG_INFO    => 'info',
  565.             PEAR_LOG_DEBUG   => 'debug'
  566.         );
  567.  
  568.         return $levels[$priority];
  569.     }
  570.  
  571.     /**
  572.      * Returns the the PEAR_LOG_* integer constant for the given string
  573.      * representation of a priority name.  This function performs a
  574.      * case-insensitive search.
  575.      *
  576.      * @param string $name      String containing a priority name.
  577.      *
  578.      * @return string           The PEAR_LOG_* integer contstant corresponding
  579.      *                          the the specified priority name.
  580.      *
  581.      * @access  public
  582.      * @since   Log 1.9.0
  583.      */
  584.     function stringToPriority($name)
  585.     {
  586.         $levels = array(
  587.             'emergency' => PEAR_LOG_EMERG,
  588.             'alert'     => PEAR_LOG_ALERT,
  589.             'critical'  => PEAR_LOG_CRIT,
  590.             'error'     => PEAR_LOG_ERR,
  591.             'warning'   => PEAR_LOG_WARNING,
  592.             'notice'    => PEAR_LOG_NOTICE,
  593.             'info'      => PEAR_LOG_INFO,
  594.             'debug'     => PEAR_LOG_DEBUG
  595.         );
  596.  
  597.         return $levels[strtolower($name)];
  598.     }
  599.  
  600.     /**
  601.      * Calculate the log mask for the given priority.
  602.      *
  603.      * This method may be called statically.
  604.      *
  605.      * @param integer   $priority   The priority whose mask will be calculated.
  606.      *
  607.      * @return integer  The calculated log mask.
  608.      *
  609.      * @access  public
  610.      * @since   Log 1.7.0
  611.      */
  612.     function MASK($priority)
  613.     {
  614.         return (1 << $priority);
  615.     }
  616.  
  617.     /**
  618.      * Calculate the log mask for all priorities up to the given priority.
  619.      *
  620.      * This method may be called statically.
  621.      *
  622.      * @param integer   $priority   The maximum priority covered by this mask.
  623.      *
  624.      * @return integer  The resulting log mask.
  625.      *
  626.      * @access  public
  627.      * @since   Log 1.7.0
  628.      *
  629.      * @deprecated deprecated since Log 1.9.4; use Log::MAX() instead
  630.      */
  631.     function UPTO($priority)
  632.     {
  633.         return Log::MAX($priority);
  634.     }
  635.  
  636.     /**
  637.      * Calculate the log mask for all priorities greater than or equal to the
  638.      * given priority.  In other words, $priority will be the lowest priority
  639.      * matched by the resulting mask.
  640.      *
  641.      * This method may be called statically.
  642.      *
  643.      * @param integer   $priority   The minimum priority covered by this mask.
  644.      *
  645.      * @return integer  The resulting log mask.
  646.      *
  647.      * @access  public
  648.      * @since   Log 1.9.4
  649.      */
  650.     function MIN($priority)
  651.     {
  652.         return PEAR_LOG_ALL ^ ((1 << $priority) - 1);
  653.     }
  654.  
  655.     /**
  656.      * Calculate the log mask for all priorities less than or equal to the
  657.      * given priority.  In other words, $priority will be the highests priority
  658.      * matched by the resulting mask.
  659.      *
  660.      * This method may be called statically.
  661.      *
  662.      * @param integer   $priority   The maximum priority covered by this mask.
  663.      *
  664.      * @return integer  The resulting log mask.
  665.      *
  666.      * @access  public
  667.      * @since   Log 1.9.4
  668.      */
  669.     function MAX($priority)
  670.     {
  671.         return ((1 << ($priority + 1)) - 1);
  672.     }
  673.  
  674.     /**
  675.      * Set and return the level mask for the current Log instance.
  676.      *
  677.      * @param integer $mask     A bitwise mask of log levels.
  678.      *
  679.      * @return integer          The current level mask.
  680.      *
  681.      * @access  public
  682.      * @since   Log 1.7.0
  683.      */
  684.     function setMask($mask)
  685.     {
  686.         $this->_mask = $mask;
  687.  
  688.         return $this->_mask;
  689.     }
  690.  
  691.     /**
  692.      * Returns the current level mask.
  693.      *
  694.      * @return interger         The current level mask.
  695.      *
  696.      * @access  public
  697.      * @since   Log 1.7.0
  698.      */
  699.     function getMask()
  700.     {
  701.         return $this->_mask;
  702.     }
  703.  
  704.     /**
  705.      * Check if the given priority is included in the current level mask.
  706.      *
  707.      * @param integer   $priority   The priority to check.
  708.      *
  709.      * @return boolean  True if the given priority is included in the current
  710.      *                  log mask.
  711.      *
  712.      * @access  protected
  713.      * @since   Log 1.7.0
  714.      */
  715.     function _isMasked($priority)
  716.     {
  717.         return (Log::MASK($priority) & $this->_mask);
  718.     }
  719.  
  720.     /**
  721.      * Returns the current default priority.
  722.      *
  723.      * @return integer  The current default priority.
  724.      *
  725.      * @access  public
  726.      * @since   Log 1.8.4
  727.      */
  728.     function getPriority()
  729.     {
  730.         return $this->_priority;
  731.     }
  732.  
  733.     /**
  734.      * Sets the default priority to the specified value.
  735.      *
  736.      * @param   integer $priority   The new default priority.
  737.      *
  738.      * @access  public
  739.      * @since   Log 1.8.4
  740.      */
  741.     function setPriority($priority)
  742.     {
  743.         $this->_priority = $priority;
  744.     }
  745.  
  746.     /**
  747.      * Adds a Log_observer instance to the list of observers that are listening
  748.      * for messages emitted by this Log instance.
  749.      *
  750.      * @param object    $observer   The Log_observer instance to attach as a
  751.      *                              listener.
  752.      *
  753.      * @param boolean   True if the observer is successfully attached.
  754.      *
  755.      * @access  public
  756.      * @since   Log 1.0
  757.      */
  758.     function attach(&$observer)
  759.     {
  760.         if (!is_a($observer, 'Log_observer')) {
  761.             return false;
  762.         }
  763.  
  764.         $this->_listeners[$observer->_id] = &$observer;
  765.  
  766.         return true;
  767.     }
  768.  
  769.     /**
  770.      * Removes a Log_observer instance from the list of observers.
  771.      *
  772.      * @param object    $observer   The Log_observer instance to detach from
  773.      *                              the list of listeners.
  774.      *
  775.      * @param boolean   True if the observer is successfully detached.
  776.      *
  777.      * @access  public
  778.      * @since   Log 1.0
  779.      */
  780.     function detach($observer)
  781.     {
  782.         if (!is_a($observer, 'Log_observer') ||
  783.             !isset($this->_listeners[$observer->_id])) {
  784.             return false;
  785.         }
  786.  
  787.         unset($this->_listeners[$observer->_id]);
  788.  
  789.         return true;
  790.     }
  791.  
  792.     /**
  793.      * Informs each registered observer instance that a new message has been
  794.      * logged.
  795.      *
  796.      * @param array     $event      A hash describing the log event.
  797.      *
  798.      * @access protected
  799.      */
  800.     function _announce($event)
  801.     {
  802.         foreach ($this->_listeners as $id => $listener) {
  803.             if ($event['priority'] <= $this->_listeners[$id]->_priority) {
  804.                 $this->_listeners[$id]->notify($event);
  805.             }
  806.         }
  807.     }
  808.  
  809.     /**
  810.      * Indicates whether this is a composite class.
  811.      *
  812.      * @return boolean          True if this is a composite class.
  813.      *
  814.      * @access  public
  815.      * @since   Log 1.0
  816.      */
  817.     function isComposite()
  818.     {
  819.         return false;
  820.     }
  821.  
  822.     /**
  823.      * Sets this Log instance's identification string.
  824.      *
  825.      * @param string    $ident      The new identification string.
  826.      *
  827.      * @access  public
  828.      * @since   Log 1.6.3
  829.      */
  830.     function setIdent($ident)
  831.     {
  832.         $this->_ident = $ident;
  833.     }
  834.  
  835.     /**
  836.      * Returns the current identification string.
  837.      *
  838.      * @return string   The current Log instance's identification string.
  839.      *
  840.      * @access  public
  841.      * @since   Log 1.6.3
  842.      */
  843.     function getIdent()
  844.     {
  845.         return $this->_ident;
  846.     }
  847. }
  848.