PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/Log/Log.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 832 lines | 295 code | 63 blank | 474 comment | 22 complexity | ee9808a4978ea5dee3ab169adece49a5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: Log.php 1336 2008-03-31 17:06:23Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage Log
  8. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * $Header$
  20. * $Horde: horde/lib/Log.php,v 1.15 2000/06/29 23:39:45 jon Exp $
  21. *
  22. * @version $ Revision: 1.51 $
  23. * @package Log
  24. */
  25. define('PEAR_LOG_EMERG', 0); /** System is unusable */
  26. define('PEAR_LOG_ALERT', 1); /** Immediate action required */
  27. define('PEAR_LOG_CRIT', 2); /** Critical conditions */
  28. define('PEAR_LOG_ERR', 3); /** Error conditions */
  29. define('PEAR_LOG_WARNING', 4); /** Warning conditions */
  30. define('PEAR_LOG_NOTICE', 5); /** Normal but significant */
  31. define('PEAR_LOG_INFO', 6); /** Informational */
  32. define('PEAR_LOG_DEBUG', 7); /** Debug-level messages */
  33. define('PEAR_LOG_TIP', 8); /** Advice messages */
  34. define('PEAR_LOG_ALL', bindec('11111111')); /** All messages */
  35. define('PEAR_LOG_NONE', bindec('00000000')); /** No message */
  36. /* Log types for PHP's native error_log() function. */
  37. define('PEAR_LOG_TYPE_SYSTEM', 0); /** Use PHP's system logger */
  38. define('PEAR_LOG_TYPE_MAIL', 1); /** Use PHP's mail() function */
  39. define('PEAR_LOG_TYPE_DEBUG', 2); /** Use PHP's debugging connection */
  40. define('PEAR_LOG_TYPE_FILE', 3); /** Append to a file */
  41. /**
  42. * The Log:: class implements both an abstraction for various logging
  43. * mechanisms and the Subject end of a Subject-Observer pattern.
  44. *
  45. * @author Chuck Hagenbuch <chuck@horde.org>
  46. * @author Jon Parise <jon@php.net>
  47. * @since Horde 1.3
  48. * @package Log
  49. */
  50. class vmLog
  51. {
  52. /**
  53. * Indicates whether or not the log can been opened / connected.
  54. *
  55. * @var boolean
  56. * @access private
  57. */
  58. var $_opened = false;
  59. /**
  60. * Instance-specific unique identification number.
  61. *
  62. * @var integer
  63. * @access private
  64. */
  65. var $_id = 0;
  66. /**
  67. * The label that uniquely identifies this set of log messages.
  68. *
  69. * @var string
  70. * @access private
  71. */
  72. var $_ident = '';
  73. /**
  74. * The default priority to use when logging an event.
  75. *
  76. * @var integer
  77. * @access private
  78. */
  79. var $_priority = PEAR_LOG_INFO;
  80. /**
  81. * The bitmask of allowed log levels.
  82. * @var integer
  83. * @access private
  84. */
  85. var $_mask = PEAR_LOG_ALL;
  86. /**
  87. * Holds all Log_observer objects that wish to be notified of new messages.
  88. *
  89. * @var array
  90. * @access private
  91. */
  92. var $_listeners = array();
  93. /**
  94. * Counts all log messages
  95. *
  96. * @var int
  97. * @access private
  98. */
  99. var $_ticker = 0;
  100. /**
  101. * Attempts to return a concrete Log instance of type $handler.
  102. *
  103. * @param string $handler The type of concrete Log subclass to return.
  104. * Attempt to dynamically include the code for
  105. * this subclass. Currently, valid values are
  106. * 'console', 'syslog', 'sql', 'file', and 'mcal'.
  107. *
  108. * @param string $name The name of the actually log file, table, or
  109. * other specific store to use. Defaults to an
  110. * empty string, with which the subclass will
  111. * attempt to do something intelligent.
  112. *
  113. * @param string $ident The identity reported to the log system.
  114. *
  115. * @param array $conf A hash containing any additional configuration
  116. * information that a subclass might need.
  117. *
  118. * @param int $level Log messages up to and including this level.
  119. *
  120. * @return Log Log The newly created concrete Log instance, or an
  121. * false on an error.
  122. * @access public
  123. * @since Log 1.0
  124. */
  125. function &factory($handler, $name = '', $ident = '', $conf = array(),
  126. $level = PEAR_LOG_DEBUG)
  127. {
  128. $obj = false;
  129. $handler = strtolower($handler);
  130. $class = 'vmLog_' . $handler;
  131. $classfile = CLASSPATH.'Log/' . $handler . '.php';
  132. /*
  133. * Attempt to include our version of the named class, but don't treat
  134. * a failure as fatal. The caller may have already included their own
  135. * version of the named class.
  136. */
  137. if (!class_exists($class)) {
  138. @include_once $classfile;
  139. }
  140. /* If the class exists, return a new instance of it. */
  141. if (class_exists($class)) {
  142. $obj = new $class($name, $ident, $conf, $level);
  143. return $obj;
  144. }
  145. return $obj;
  146. }
  147. /**
  148. * Attempts to return a reference to a concrete Log instance of type
  149. * $handler, only creating a new instance if no log instance with the same
  150. * parameters currently exists.
  151. *
  152. * You should use this if there are multiple places you might create a
  153. * logger, you don't want to create multiple loggers, and you don't want to
  154. * check for the existance of one each time. The singleton pattern does all
  155. * the checking work for you.
  156. *
  157. * <b>You MUST call this method with the $var = &Log::singleton() syntax.
  158. * Without the ampersand (&) in front of the method name, you will not get
  159. * a reference, you will get a copy.</b>
  160. *
  161. * @param string $handler The type of concrete Log subclass to return.
  162. * Attempt to dynamically include the code for
  163. * this subclass. Currently, valid values are
  164. * 'console', 'syslog', 'sql', 'file', and 'mcal'.
  165. *
  166. * @param string $name The name of the actually log file, table, or
  167. * other specific store to use. Defaults to an
  168. * empty string, with which the subclass will
  169. * attempt to do something intelligent.
  170. *
  171. * @param string $ident The identity reported to the log system.
  172. *
  173. * @param array $conf A hash containing any additional configuration
  174. * information that a subclass might need.
  175. *
  176. * @param int $level Log messages up to and including this level.
  177. *
  178. * @return object Log The newly created concrete Log instance, or an
  179. * false on an error.
  180. * @access public
  181. * @since Log 1.0
  182. */
  183. function &singleton($handler, $name = '', $ident = '', $conf = array(),
  184. $level = PEAR_LOG_DEBUG)
  185. {
  186. static $instances;
  187. if (!isset($instances)) $instances = array();
  188. $signature = serialize(array($handler, $name, $ident, $conf, $level));
  189. if (!isset($instances[$signature])) {
  190. $instances[$signature] = &vmLog::factory($handler, $name, $ident,
  191. $conf, $level);
  192. }
  193. return $instances[$signature];
  194. }
  195. /**
  196. * Abstract implementation of the open() method.
  197. * @since Log 1.0
  198. */
  199. function open()
  200. {
  201. return false;
  202. }
  203. /**
  204. * Abstract implementation of the close() method.
  205. * @since Log 1.0
  206. */
  207. function close()
  208. {
  209. return false;
  210. }
  211. /**
  212. * Abstract implementation of the flush() method.
  213. * @since Log 1.8.2
  214. */
  215. function flush()
  216. {
  217. return false;
  218. }
  219. /**
  220. * Abstract implementation of the log() method.
  221. * @since Log 1.0
  222. */
  223. function log($message, $priority = null)
  224. {
  225. return false;
  226. }
  227. /**
  228. * A convenience function for logging a emergency event. It will log a
  229. * message at the PEAR_LOG_EMERG log level.
  230. *
  231. * @param mixed $message String or object containing the message
  232. * to log.
  233. *
  234. * @return boolean True if the message was successfully logged.
  235. *
  236. * @access public
  237. * @since Log 1.7.0
  238. */
  239. function emerg($message)
  240. {
  241. return $this->log($message, PEAR_LOG_EMERG);
  242. }
  243. /**
  244. * A convenience function for logging an alert event. It will log a
  245. * message at the PEAR_LOG_ALERT log level.
  246. *
  247. * @param mixed $message String or object containing the message
  248. * to log.
  249. *
  250. * @return boolean True if the message was successfully logged.
  251. *
  252. * @access public
  253. * @since Log 1.7.0
  254. */
  255. function alert($message)
  256. {
  257. return $this->log($message, PEAR_LOG_ALERT);
  258. }
  259. /**
  260. * A convenience function for logging a critical event. It will log a
  261. * message at the PEAR_LOG_CRIT log level.
  262. *
  263. * @param mixed $message String or object containing the message
  264. * to log.
  265. *
  266. * @return boolean True if the message was successfully logged.
  267. *
  268. * @access public
  269. * @since Log 1.7.0
  270. */
  271. function crit($message)
  272. {
  273. return $this->log($message, PEAR_LOG_CRIT);
  274. }
  275. /**
  276. * A convenience function for logging a error event. It will log a
  277. * message at the PEAR_LOG_ERR log level.
  278. *
  279. * @param mixed $message String or object containing the message
  280. * to log.
  281. *
  282. * @return boolean True if the message was successfully logged.
  283. *
  284. * @access public
  285. * @since Log 1.7.0
  286. */
  287. function err($message)
  288. {
  289. return $this->log($message, PEAR_LOG_ERR);
  290. }
  291. /**
  292. * A convenience function for logging a warning event. It will log a
  293. * message at the PEAR_LOG_WARNING log level.
  294. *
  295. * @param mixed $message String or object containing the message
  296. * to log.
  297. *
  298. * @return boolean True if the message was successfully logged.
  299. *
  300. * @access public
  301. * @since Log 1.7.0
  302. */
  303. function warning($message)
  304. {
  305. return $this->log($message, PEAR_LOG_WARNING);
  306. }
  307. /**
  308. * A convenience function for logging a notice event. It will log a
  309. * message at the PEAR_LOG_NOTICE log level.
  310. *
  311. * @param mixed $message String or object containing the message
  312. * to log.
  313. *
  314. * @return boolean True if the message was successfully logged.
  315. *
  316. * @access public
  317. * @since Log 1.7.0
  318. */
  319. function notice($message)
  320. {
  321. return $this->log($message, PEAR_LOG_NOTICE);
  322. }
  323. /**
  324. * A convenience function for logging a information event. It will log a
  325. * message at the PEAR_LOG_INFO log level.
  326. *
  327. * @param mixed $message String or object containing the message
  328. * to log.
  329. *
  330. * @return boolean True if the message was successfully logged.
  331. *
  332. * @access public
  333. * @since Log 1.7.0
  334. */
  335. function info($message)
  336. {
  337. return $this->log($message, PEAR_LOG_INFO);
  338. }
  339. /**
  340. * A convenience function for logging a debug event. It will log a
  341. * message at the PEAR_LOG_DEBUG log level.
  342. *
  343. * @param mixed $message String or object containing the message
  344. * to log.
  345. *
  346. * @return boolean True if the message was successfully logged.
  347. *
  348. * @access public
  349. * @since Log 1.7.0
  350. */
  351. function debug($message)
  352. {
  353. return $this->log($message, PEAR_LOG_DEBUG);
  354. }
  355. /**
  356. * A convenience function for logging an advice event. It will log a
  357. * message at the PEAR_LOG_TIP log level.
  358. *
  359. * @param mixed $message String or object containing the message
  360. * to log.
  361. *
  362. * @return boolean True if the message was successfully logged.
  363. * @author soeren
  364. * @access public
  365. * @since Log 1.9.0
  366. */
  367. function tip($message)
  368. {
  369. return $this->log($message, PEAR_LOG_TIP);
  370. }
  371. /**
  372. * Returns the string representation of the message data.
  373. *
  374. * If $message is an object, _extractMessage() will attempt to extract
  375. * the message text using a known method (such as a PEAR_Error object's
  376. * getMessage() method). If a known method, cannot be found, the
  377. * serialized representation of the object will be returned.
  378. *
  379. * If the message data is already a string, it will be returned unchanged.
  380. *
  381. * @param mixed $message The original message data. This may be a
  382. * string or any object.
  383. *
  384. * @return string The string representation of the message.
  385. *
  386. * @access private
  387. */
  388. function _extractMessage($message)
  389. {
  390. /*
  391. * If we've been given an object, attempt to extract the message using
  392. * a known method. If we can't find such a method, default to the
  393. * "human-readable" version of the object.
  394. *
  395. * We also use the human-readable format for arrays.
  396. */
  397. if (is_object($message)) {
  398. if (method_exists($message, 'getmessage')) {
  399. $message = $message->getMessage();
  400. } else if (method_exists($message, 'tostring')) {
  401. $message = $message->toString();
  402. } else if (method_exists($message, '__tostring')) {
  403. if (version_compare(PHP_VERSION, '5.0.0', 'ge')) {
  404. $message = (string)$message;
  405. } else {
  406. $message = $message->__toString();
  407. }
  408. } else {
  409. $message = print_r($message, true);
  410. }
  411. } else if (is_array($message)) {
  412. if (isset($message['message'])) {
  413. $message = $message['message'];
  414. } else {
  415. $message = print_r($message, true);
  416. }
  417. }
  418. /* Otherwise, we assume the message is a string. */
  419. return $message;
  420. }
  421. /**
  422. * Returns the string representation of a PEAR_LOG_* integer constant.
  423. *
  424. * @param int $priority A PEAR_LOG_* integer constant.
  425. *
  426. * @return string The string representation of $level.
  427. *
  428. * @since Log 1.0
  429. */
  430. function priorityToString($priority)
  431. {
  432. global $VM_LANG;
  433. $levels = array(
  434. PEAR_LOG_EMERG => $VM_LANG->_('PEAR_LOG_EMERG'),
  435. PEAR_LOG_ALERT => $VM_LANG->_('PEAR_LOG_ALERT'),
  436. PEAR_LOG_CRIT => $VM_LANG->_('PEAR_LOG_CRIT'),
  437. PEAR_LOG_ERR => $VM_LANG->_('PEAR_LOG_ERR'),
  438. PEAR_LOG_WARNING => $VM_LANG->_('PEAR_LOG_WARNING'),
  439. PEAR_LOG_NOTICE => $VM_LANG->_('PEAR_LOG_NOTICE'),
  440. PEAR_LOG_INFO => $VM_LANG->_('PEAR_LOG_INFO'),
  441. PEAR_LOG_DEBUG => $VM_LANG->_('PEAR_LOG_DEBUG'),
  442. PEAR_LOG_TIP => $VM_LANG->_('PEAR_LOG_TIP')
  443. );
  444. return $levels[$priority];
  445. }
  446. /**
  447. * Returns the the PEAR_LOG_* integer constant for the given string
  448. * representation of a priority name. This function performs a
  449. * case-insensitive search.
  450. *
  451. * @param string $name String containing a priority name.
  452. *
  453. * @return string The PEAR_LOG_* integer contstant corresponding
  454. * the the specified priority name.
  455. *
  456. * @since Log 1.9.0
  457. */
  458. function stringToPriority($name)
  459. {
  460. global $VM_LANG;
  461. $levels = array(
  462. $VM_LANG->_('PEAR_LOG_EMERG') => PEAR_LOG_EMERG,
  463. $VM_LANG->_('PEAR_LOG_ALERT') => PEAR_LOG_ALERT,
  464. $VM_LANG->_('PEAR_LOG_CRIT') => PEAR_LOG_CRIT,
  465. $VM_LANG->_('PEAR_LOG_ERR') => PEAR_LOG_ERR,
  466. $VM_LANG->_('PEAR_LOG_WARNING') => PEAR_LOG_WARNING,
  467. $VM_LANG->_('PEAR_LOG_NOTICE') => PEAR_LOG_NOTICE,
  468. $VM_LANG->_('PEAR_LOG_INFO') => PEAR_LOG_INFO,
  469. $VM_LANG->_('PEAR_LOG_DEBUG') => PEAR_LOG_DEBUG,
  470. $VM_LANG->_('PEAR_LOG_TIP') => PEAR_LOG_TIP
  471. );
  472. return $levels[strtolower($name)];
  473. }
  474. /*
  475. @MWM: There was a typo in at least common/english.php for PEAR_LOG_TIP.
  476. Note that correct text is needed to ensure proper conversion from number
  477. to text (and vice-versa). For this and other reasons, I'm creating the
  478. conversion functions below and use names based on the __same name as the
  479. actual constant__ for file logging.
  480. In general, I don't think that the logging level should be subject to
  481. translation errors. Moreover, the log messages themselves are in
  482. English, so it seems pointless to translate just the logging level.
  483. */
  484. /**
  485. * Convert a priorty name to a priority number.
  486. * Name is based on actual priority name.
  487. *
  488. * @param string $name String containing a priority name.
  489. * @return string The PEAR_LOG_* integer contstant corresponding
  490. * to the specified priority name.
  491. */
  492. function stringToPriorityPEAR($name)
  493. {
  494. global $VM_LANG;
  495. $levels = array(
  496. 'PEAR_LOG_EMERG' => PEAR_LOG_EMERG,
  497. 'PEAR_LOG_ALERT' => PEAR_LOG_ALERT,
  498. 'PEAR_LOG_CRIT' => PEAR_LOG_CRIT,
  499. 'PEAR_LOG_ERR' => PEAR_LOG_ERR,
  500. 'PEAR_LOG_WARNING' => PEAR_LOG_WARNING,
  501. 'PEAR_LOG_NOTICE' => PEAR_LOG_NOTICE,
  502. 'PEAR_LOG_INFO' => PEAR_LOG_INFO,
  503. 'PEAR_LOG_DEBUG' => PEAR_LOG_DEBUG,
  504. 'PEAR_LOG_TIP' => PEAR_LOG_TIP
  505. );
  506. return $levels[$name];
  507. }
  508. /**
  509. * Returns the string representation of a PEAR_LOG_* integer constant.
  510. * Name is based on actual priority name.
  511. *
  512. * @param int $priority A PEAR_LOG_* integer constant.
  513. *
  514. * @return string The string representation of $priority.
  515. *
  516. */
  517. function priorityToStringPEAR($priority)
  518. {
  519. global $VM_LANG;
  520. $levels = array(
  521. PEAR_LOG_EMERG => 'PEAR_LOG_EMERG',
  522. PEAR_LOG_ALERT => 'PEAR_LOG_ALERT',
  523. PEAR_LOG_CRIT => 'PEAR_LOG_CRIT',
  524. PEAR_LOG_ERR => 'PEAR_LOG_ERR',
  525. PEAR_LOG_WARNING => 'PEAR_LOG_WARNING',
  526. PEAR_LOG_NOTICE => 'PEAR_LOG_NOTICE',
  527. PEAR_LOG_INFO => 'PEAR_LOG_INFO',
  528. PEAR_LOG_DEBUG => 'PEAR_LOG_DEBUG',
  529. PEAR_LOG_TIP => 'PEAR_LOG_TIP'
  530. );
  531. return $levels[$priority];
  532. }
  533. /**
  534. * Returns the string representation of a PEAR_LOG_* integer constant.
  535. * Name is a shortened version of the actual priority name.
  536. *
  537. * @param int $priority A PEAR_LOG_* integer constant.
  538. *
  539. * @return string The string representation of $priority.
  540. *
  541. */
  542. function priorityToShortStringPEAR($priority)
  543. {
  544. global $VM_LANG;
  545. $levels = array(
  546. PEAR_LOG_EMERG => 'EMERG',
  547. PEAR_LOG_ALERT => 'ALERT',
  548. PEAR_LOG_CRIT => 'CRIT',
  549. PEAR_LOG_ERR => 'ERR',
  550. PEAR_LOG_WARNING => 'WARNING',
  551. PEAR_LOG_NOTICE => 'NOTICE',
  552. PEAR_LOG_INFO => 'INFO',
  553. PEAR_LOG_DEBUG => 'DEBUG',
  554. PEAR_LOG_TIP => 'TIP'
  555. );
  556. return $levels[$priority];
  557. }
  558. /**
  559. * Convert a short priorty name to a priority number.
  560. * Name is based on actual priority name.
  561. *
  562. * @param string $name String containing a priority name.
  563. * @return string The PEAR_LOG_* integer contstant corresponding
  564. * to the specified priority name.
  565. */
  566. function shortStringToPriorityPEAR($name)
  567. {
  568. global $VM_LANG;
  569. $levels = array(
  570. 'EMERG' => PEAR_LOG_EMERG,
  571. 'ALERT' => PEAR_LOG_ALERT,
  572. 'CRIT' => PEAR_LOG_CRIT,
  573. 'ERR' => PEAR_LOG_ERR,
  574. 'WARNING' => PEAR_LOG_WARNING,
  575. 'NOTICE' => PEAR_LOG_NOTICE,
  576. 'INFO' => PEAR_LOG_INFO,
  577. 'DEBUG' => PEAR_LOG_DEBUG,
  578. 'TIP' => PEAR_LOG_TIP
  579. );
  580. return $levels[$name];
  581. }
  582. /**
  583. * Calculate the log mask for the given priority.
  584. *
  585. * @param integer $priority The priority whose mask will be calculated.
  586. *
  587. * @return integer The calculated log mask.
  588. *
  589. * @access public
  590. * @since Log 1.7.0
  591. */
  592. function MASK($priority)
  593. {
  594. return (1 << $priority);
  595. }
  596. /**
  597. * Calculate the log mask for all priorities up to the given priority.
  598. *
  599. * @param integer $priority The maximum priority covered by this mask.
  600. *
  601. * @return integer The calculated log mask.
  602. *
  603. * @access public
  604. * @since Log 1.7.0
  605. */
  606. function UPTO($priority)
  607. {
  608. return ((1 << ($priority + 1)) - 1);
  609. }
  610. /**
  611. * Set and return the level mask for the current Log instance.
  612. *
  613. * @param integer $mask A bitwise mask of log levels.
  614. *
  615. * @return integer The current level mask.
  616. *
  617. * @access public
  618. * @since Log 1.7.0
  619. */
  620. function setMask($mask)
  621. {
  622. $this->_mask = $mask;
  623. return $this->_mask;
  624. }
  625. /**
  626. * Returns the current level mask.
  627. *
  628. * @return interger The current level mask.
  629. *
  630. * @access public
  631. * @since Log 1.7.0
  632. */
  633. function getMask()
  634. {
  635. return $this->_mask;
  636. }
  637. /**
  638. * Check if the given priority is included in the current level mask.
  639. *
  640. * @param integer $priority The priority to check.
  641. *
  642. * @return boolean True if the given priority is included in the current
  643. * log mask.
  644. *
  645. * @access private
  646. * @since Log 1.7.0
  647. */
  648. function _isMasked($priority)
  649. {
  650. return (vmLog::MASK($priority) & $this->_mask);
  651. }
  652. /**
  653. * Returns the current default priority.
  654. *
  655. * @return integer The current default priority.
  656. *
  657. * @access public
  658. * @since Log 1.8.4
  659. */
  660. function getPriority()
  661. {
  662. return $this->_priority;
  663. }
  664. /**
  665. * Sets the default priority to the specified value.
  666. *
  667. * @param integer $priority The new default priority.
  668. *
  669. * @access public
  670. * @since Log 1.8.4
  671. */
  672. function setPriority($priority)
  673. {
  674. $this->_priority = $priority;
  675. }
  676. /**
  677. * Adds a Log_observer instance to the list of observers that are listening
  678. * for messages emitted by this Log instance.
  679. *
  680. * @param object $observer The Log_observer instance to attach as a
  681. * listener.
  682. *
  683. * @param boolean True if the observer is successfully attached.
  684. *
  685. * @access public
  686. * @since Log 1.0
  687. */
  688. function attach(&$observer)
  689. {
  690. if (!is_a($observer, 'Log_observer')) {
  691. return false;
  692. }
  693. $this->_listeners[$observer->_id] = &$observer;
  694. return true;
  695. }
  696. /**
  697. * Removes a Log_observer instance from the list of observers.
  698. *
  699. * @param object $observer The Log_observer instance to detach from
  700. * the list of listeners.
  701. *
  702. * @param boolean True if the observer is successfully detached.
  703. *
  704. * @access public
  705. * @since Log 1.0
  706. */
  707. function detach($observer)
  708. {
  709. if (!is_a($observer, 'Log_observer') ||
  710. !isset($this->_listeners[$observer->_id])) {
  711. return false;
  712. }
  713. unset($this->_listeners[$observer->_id]);
  714. return true;
  715. }
  716. /**
  717. * Informs each registered observer instance that a new message has been
  718. * logged.
  719. *
  720. * @param array $event A hash describing the log event.
  721. *
  722. * @access private
  723. */
  724. function _announce($event)
  725. {
  726. foreach ($this->_listeners as $id => $listener) {
  727. if ($event['priority'] <= $this->_listeners[$id]->_priority) {
  728. $this->_listeners[$id]->notify($event);
  729. }
  730. }
  731. }
  732. /**
  733. * Indicates whether this is a composite class.
  734. *
  735. * @return boolean True if this is a composite class.
  736. *
  737. * @access public
  738. * @since Log 1.0
  739. */
  740. function isComposite()
  741. {
  742. return false;
  743. }
  744. /**
  745. * Sets this Log instance's identification string.
  746. *
  747. * @param string $ident The new identification string.
  748. *
  749. * @access public
  750. * @since Log 1.6.3
  751. */
  752. function setIdent($ident)
  753. {
  754. $this->_ident = $ident;
  755. }
  756. /**
  757. * Returns the current identification string.
  758. *
  759. * @return string The current Log instance's identification string.
  760. *
  761. * @access public
  762. * @since Log 1.6.3
  763. */
  764. function getIdent()
  765. {
  766. return $this->_ident;
  767. }
  768. }
  769. ?>