PageRenderTime 96ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/php/Log/observer.php

https://bitbucket.org/adarshj/convenient_website
PHP | 126 lines | 42 code | 11 blank | 73 comment | 6 complexity | 12b863e4f0e614843cd1176fa6e39506 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * $Header: /repository/pear/Log/Log/observer.php,v 1.12 2004/01/11 20:49:49 jon Exp $
  4. * $Horde: horde/lib/Log/observer.php,v 1.5 2000/06/28 21:36:13 jon Exp $
  5. *
  6. * @version $Revision: 1.12 $
  7. * @package Log
  8. */
  9. /**
  10. * The Log_observer:: class implements the Observer end of a Subject-Observer
  11. * pattern for watching log activity and taking actions on exceptional events.
  12. *
  13. * @author Chuck Hagenbuch <chuck@horde.org>
  14. * @since Horde 1.3
  15. * @since Log 1.0
  16. * @package Log
  17. *
  18. * @example observer_mail.php An example Log_observer implementation.
  19. */
  20. class Log_observer
  21. {
  22. /**
  23. * Instance-specific unique identification number.
  24. *
  25. * @var integer
  26. * @access private
  27. */
  28. var $_id = 0;
  29. /**
  30. * The minimum priority level of message that we want to hear about.
  31. * PEAR_LOG_EMERG is the highest priority, so we will only hear messages
  32. * with an integer priority value less than or equal to ours. It defaults
  33. * to PEAR_LOG_INFO, which listens to everything except PEAR_LOG_DEBUG.
  34. *
  35. * @var string
  36. * @access private
  37. */
  38. var $_priority = PEAR_LOG_INFO;
  39. /**
  40. * Creates a new basic Log_observer instance.
  41. *
  42. * @param integer $priority The highest priority at which to receive
  43. * log event notifications.
  44. *
  45. * @access public
  46. */
  47. function Log_observer($priority = PEAR_LOG_INFO)
  48. {
  49. $this->_id = md5(microtime());
  50. $this->_priority = $priority;
  51. }
  52. /**
  53. * Attempts to return a new concrete Log_observer instance of the requested
  54. * type.
  55. *
  56. * @param string $type The type of concreate Log_observer subclass
  57. * to return.
  58. * @param integer $priority The highest priority at which to receive
  59. * log event notifications.
  60. * @param array $conf Optional associative array of additional
  61. * configuration values.
  62. *
  63. * @return object The newly created concrete Log_observer
  64. * instance, or an false on an error.
  65. */
  66. function &factory($type, $priority = PEAR_LOG_INFO, $conf = array())
  67. {
  68. $type = strtolower($type);
  69. $class = 'Log_observer_' . $type;
  70. /* Support both the new-style and old-style file naming conventions. */
  71. if (file_exists(dirname(__FILE__) . '/observer_' . $type . '.php')) {
  72. $classfile = 'Log/observer_' . $type . '.php';
  73. $newstyle = true;
  74. } else {
  75. $classfile = 'Log/' . $type . '.php';
  76. $newstyle = false;
  77. }
  78. /* Issue a warning if the old-style conventions are being used. */
  79. if (!$newstyle)
  80. {
  81. trigger_error('Using old-style Log_observer conventions',
  82. E_USER_WARNING);
  83. }
  84. /*
  85. * Attempt to include our version of the named class, but don't treat
  86. * a failure as fatal. The caller may have already included their own
  87. * version of the named class.
  88. */
  89. @include_once $classfile;
  90. /* If the class exists, return a new instance of it. */
  91. if (class_exists($class)) {
  92. /* Support both new-style and old-style construction. */
  93. if ($newstyle) {
  94. return new $class($priority, $conf);
  95. } else {
  96. return new $class($priority);
  97. }
  98. }
  99. return false;
  100. }
  101. /**
  102. * This is a stub method to make sure that Log_Observer classes do
  103. * something when they are notified of a message. The default behavior
  104. * is to just print the message, which is obviously not desireable in
  105. * practically any situation - which is why you need to override this
  106. * method. :)
  107. *
  108. * @param array $event A hash describing the log event.
  109. */
  110. function notify($event)
  111. {
  112. print_r($event);
  113. }
  114. }
  115. ?>