| 1 |
<?php |
<?php |
| 2 |
// $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $ |
// $Id$ |
| 3 |
|
// $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $ |
| 4 |
/** |
|
| 5 |
* The Log_composite:: class implements a Composite pattern which |
/** |
| 6 |
* allows multiple Log implementations to get sent the same events. |
* The Log_composite:: class implements a Composite pattern which |
| 7 |
* |
* allows multiple Log implementations to get sent the same events. |
| 8 |
* @author Chuck Hagenbuch <chuck@horde.org> |
* |
| 9 |
* @version $Revision$ |
* @author Chuck Hagenbuch <chuck@horde.org> |
| 10 |
* @since Horde 1.3 |
* @version $Revision$ |
| 11 |
*/ |
* @since Horde 1.3 |
| 12 |
class Log_composite { |
* @package Log |
| 13 |
|
*/ |
| 14 |
// {{{ properties |
|
| 15 |
|
class Log_composite extends Log { |
| 16 |
/** Array holding all Log instances which should be sent events |
|
| 17 |
sent to the composite. */ |
/** |
| 18 |
var $children = array(); |
* Array holding all Log instances |
| 19 |
|
* which should be sent events sent to the composite. |
| 20 |
// }}} |
* @var array |
| 21 |
|
*/ |
| 22 |
|
var $_children = array(); |
| 23 |
// {{{ constructor |
|
| 24 |
/** |
|
| 25 |
* Constructs a new composite Log object. |
/** |
| 26 |
* |
* Constructs a new composite Log object. |
| 27 |
* @param $log_name (optional) This is ignored. |
* |
| 28 |
* @param $ident (optional) This is ignored. |
* @param boolean $name This is ignored. |
| 29 |
* @param $conf (optional) This is ignored. |
* @param boolean $ident This is ignored. |
| 30 |
*/ |
* @param boolean $conf This is ignored. |
| 31 |
function Log_composite ($log_name = false, $ident = false, $conf = false) { |
* @param boolean $maxLevel This is ignored. |
| 32 |
} |
* @access public |
| 33 |
// }}} |
*/ |
| 34 |
|
function Log_composite($name = false, $ident = false, $conf = false, |
| 35 |
|
$maxLevel = PEAR_LOG_DEBUG) |
| 36 |
// {{{ open() |
{ |
| 37 |
/** |
} |
| 38 |
* Open the log connections of each and every child of this |
|
| 39 |
* composite. |
/** |
| 40 |
*/ |
* Open the log connections of each and every child of this |
| 41 |
function open () { |
* composite. |
| 42 |
if (!$this->opened) { |
* @access public |
| 43 |
reset($this->children); |
*/ |
| 44 |
foreach ($this->children as $child) { |
function open() |
| 45 |
$child->open(); |
{ |
| 46 |
} |
if (!$this->_opened) { |
| 47 |
} |
reset($this->_children); |
| 48 |
} |
foreach ($this->_children as $child) { |
| 49 |
// }}} |
$child->open(); |
| 50 |
|
} |
| 51 |
// {{{ close() |
} |
| 52 |
/** |
} |
| 53 |
* If we've gone ahead and opened each child, go through and close |
|
| 54 |
* each child. |
/** |
| 55 |
*/ |
* If we've gone ahead and opened each child, go through and close |
| 56 |
function close () { |
* each child. |
| 57 |
if ($this->opened) { |
* @access public |
| 58 |
reset($this->children); |
*/ |
| 59 |
foreach ($this->children as $child) { |
function close() |
| 60 |
$child->close(); |
{ |
| 61 |
} |
if ($this->_opened) { |
| 62 |
} |
reset($this->_children); |
| 63 |
} |
foreach ($this->_children as $child) { |
| 64 |
// }}} |
$child->close(); |
| 65 |
|
} |
| 66 |
// {{{ log() |
} |
| 67 |
/** |
} |
| 68 |
* Sends $message and $priority to every child of this composite. |
|
| 69 |
* |
/** |
| 70 |
* @param $message The textual message to be logged. |
* Sends $message and $priority to every child of this composite. |
| 71 |
* @param $priority (optional) The priority of the message. Valid |
* |
| 72 |
* values are: LOG_EMERG, LOG_ALERT, LOG_CRIT, |
* @param string $message The textual message to be logged. |
| 73 |
* LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, |
* @param string $priority (optional) The priority of the message. Valid |
| 74 |
* and LOG_DEBUG. The default is LOG_INFO. |
* values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, |
| 75 |
*/ |
* PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, |
| 76 |
function log ($message, $priority = LOG_INFO) { |
* PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. |
| 77 |
reset($this->children); |
* The default is PEAR_LOG_INFO. |
| 78 |
foreach ($this->children as $child) { |
* @return boolean True on success or false on failure. |
| 79 |
$child->log($message, $priority); |
*/ |
| 80 |
} |
function log($message, $priority = PEAR_LOG_INFO) |
| 81 |
|
{ |
| 82 |
$this->notifyAll(array('priority' => $priority, 'message' => $message)); |
reset($this->_children); |
| 83 |
} |
foreach ($this->_children as $child) { |
| 84 |
// }}} |
$child->log($message, $priority); |
| 85 |
|
} |
| 86 |
// {{{ isComposite() |
|
| 87 |
/** |
$this->notifyAll(array('priority' => $priority, 'message' => $message)); |
| 88 |
* @return a Boolean: true if this is a composite class, false |
|
| 89 |
* otherwise. Always returns true since this is the composite |
return true; |
| 90 |
* subclass. |
} |
| 91 |
*/ |
|
| 92 |
function isComposite () { |
/** |
| 93 |
return true; |
* @return boolean true if this is a composite class, false |
| 94 |
} |
* otherwise. Always returns true since this is the composite |
| 95 |
// }}} |
* subclass. |
| 96 |
|
* @access public |
| 97 |
// {{{ addChild() |
*/ |
| 98 |
/** |
function isComposite() |
| 99 |
* Add a Log instance to the list of children that messages sent |
{ |
| 100 |
* to us should be passed on to. |
return true; |
| 101 |
* |
} |
| 102 |
* @param $child The Log instance to add. |
|
| 103 |
*/ |
/** |
| 104 |
function addChild (&$child) { |
* Add a Log instance to the list of children that messages sent |
| 105 |
if (!is_object($child)) |
* to us should be passed on to. |
| 106 |
return false; |
* |
| 107 |
|
* @param object Log &$child The Log instance to add. |
| 108 |
$child->_childID = uniqid(rand()); |
* @access public |
| 109 |
|
* @return boolean false, if &$child isn't a Log instance |
| 110 |
$this->children[$child->_listenerID] = &$child; |
*/ |
| 111 |
} |
function addChild(&$child) |
| 112 |
// }}} |
{ |
| 113 |
|
if (!is_object($child)) { |
| 114 |
// {{{ removeChild() |
return false; |
| 115 |
/** |
} |
| 116 |
* Remove a Log instance from the list of children that messages |
|
| 117 |
* sent to us should be passed on to. |
$child->_childID = uniqid(rand()); |
| 118 |
* |
|
| 119 |
* @param $child The Log instance to remove. |
$this->_children[$child->_childID] = &$child; |
| 120 |
*/ |
} |
| 121 |
function removeChild ($child) { |
|
| 122 |
if (isset($this->children[$child->_childID])) |
/** |
| 123 |
unset($this->children[$child->_childID]); |
* Remove a Log instance from the list of children that messages |
| 124 |
} |
* sent to us should be passed on to. |
| 125 |
// }}} |
* |
| 126 |
|
* @param object Log $child The Log instance to remove. |
| 127 |
} |
* @access public |
| 128 |
|
*/ |
| 129 |
?> |
function removeChild($child) |
| 130 |
|
{ |
| 131 |
|
if (isset($this->_children[$child->_childID])) { |
| 132 |
|
unset($this->_children[$child->_childID]); |
| 133 |
|
} |
| 134 |
|
} |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
?> |