root/events/phpframework/akelos/trunk/vendor/pear/Log/composite.php
@
18146
| Revision 18146, 5.0 kB (checked in by gen, 5 years ago) |
|---|
| Line | |
|---|---|
| 1 | <?php |
| 2 | /** |
| 3 | * $Header: /repository/pear/Log/Log/composite.php,v 1.26 2005/08/24 05:09:45 jon Exp $ |
| 4 | * $Horde: horde/lib/Log/composite.php,v 1.2 2000/06/28 21:36:13 jon Exp $ |
| 5 | * |
| 6 | * @version $Revision: 1.26 $ |
| 7 | * @package Log |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * The Log_composite:: class implements a Composite pattern which |
| 12 | * allows multiple Log implementations to receive the same events. |
| 13 | * |
| 14 | * @author Chuck Hagenbuch <chuck@horde.org> |
| 15 | * @author Jon Parise <jon@php.net> |
| 16 | * |
| 17 | * @since Horde 1.3 |
| 18 | * @since Log 1.0 |
| 19 | * @package Log |
| 20 | * |
| 21 | * @example composite.php Using the composite handler. |
| 22 | */ |
| 23 | class Log_composite extends Log |
| 24 | { |
| 25 | /** |
| 26 | * Array holding all of the Log instances to which log events should be |
| 27 | * sent. |
| 28 | * |
| 29 | * @var array |
| 30 | * @access private |
| 31 | */ |
| 32 | var $_children = array(); |
| 33 | |
| 34 | |
| 35 | /** |
| 36 | * Constructs a new composite Log object. |
| 37 | * |
| 38 | * @param boolean $name This parameter is ignored. |
| 39 | * @param boolean $ident This parameter is ignored. |
| 40 | * @param boolean $conf This parameter is ignored. |
| 41 | * @param boolean $level This parameter is ignored. |
| 42 | * |
| 43 | * @access public |
| 44 | */ |
| 45 | function Log_composite($name, $ident = '', $conf = array(), |
| 46 | $level = PEAR_LOG_DEBUG) |
| 47 | { |
| 48 | $this->_ident = $ident; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Opens the child connections. |
| 53 | * |
| 54 | * @access public |
| 55 | */ |
| 56 | function open() |
| 57 | { |
| 58 | if (!$this->_opened) { |
| 59 | foreach ($this->_children as $id => $child) { |
| 60 | $this->_children[$id]->open(); |
| 61 | } |
| 62 | $this->_opened = true; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Closes any child instances. |
| 68 | * |
| 69 | * @access public |
| 70 | */ |
| 71 | function close() |
| 72 | { |
| 73 | if ($this->_opened) { |
| 74 | foreach ($this->_children as $id => $child) { |
| 75 | $this->_children[$id]->close(); |
| 76 | } |
| 77 | $this->_opened = false; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Flushes all open child instances. |
| 83 | * |
| 84 | * @access public |
| 85 | * @since Log 1.8.2 |
| 86 | */ |
| 87 | function flush() |
| 88 | { |
| 89 | if ($this->_opened) { |
| 90 | foreach ($this->_children as $id => $child) { |
| 91 | $this->_children[$id]->flush(); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sends $message and $priority to each child of this composite. |
| 98 | * |
| 99 | * @param mixed $message String or object containing the message |
| 100 | * to log. |
| 101 | * @param string $priority (optional) The priority of the message. |
| 102 | * Valid values are: PEAR_LOG_EMERG, |
| 103 | * PEAR_LOG_ALERT, PEAR_LOG_CRIT, |
| 104 | * PEAR_LOG_ERR, PEAR_LOG_WARNING, |
| 105 | * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and |
| 106 | * PEAR_LOG_DEBUG. |
| 107 | * |
| 108 | * @return boolean True if the entry is successfully logged. |
| 109 | * |
| 110 | * @access public |
| 111 | */ |
| 112 | function log($message, $priority = null) |
| 113 | { |
| 114 | /* If a priority hasn't been specified, use the default value. */ |
| 115 | if ($priority === null) { |
| 116 | $priority = $this->_priority; |
| 117 | } |
| 118 | |
| 119 | foreach ($this->_children as $id => $child) { |
| 120 | $this->_children[$id]->log($message, $priority); |
| 121 | } |
| 122 | |
| 123 | $this->_announce(array('priority' => $priority, 'message' => $message)); |
| 124 | |
| 125 | return true; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Returns true if this is a composite. |
| 130 | * |
| 131 | * @return boolean True if this is a composite class. |
| 132 | * |
| 133 | * @access public |
| 134 | */ |
| 135 | function isComposite() |
| 136 | { |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * Sets this identification string for all of this composite's children. |
| 142 | * |
| 143 | * @param string $ident The new identification string. |
| 144 | * |
| 145 | * @access public |
| 146 | * @since Log 1.6.7 |
| 147 | */ |
| 148 | function setIdent($ident) |
| 149 | { |
| 150 | /* Call our base class's setIdent() method. */ |
| 151 | parent::setIdent($ident); |
| 152 | |
| 153 | /* ... and then call setIdent() on all of our children. */ |
| 154 | foreach ($this->_children as $id => $child) { |
| 155 | $this->_children[$id]->setIdent($ident); |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Adds a Log instance to the list of children. |
| 161 | * |
| 162 | * @param object $child The Log instance to add. |
| 163 | * |
| 164 | * @return boolean True if the Log instance was successfully added. |
| 165 | * |
| 166 | * @access public |
| 167 | */ |
| 168 | function addChild(&$child) |
| 169 | { |
| 170 | /* Make sure this is a Log instance. */ |
| 171 | if (!is_a($child, 'Log')) { |
| 172 | return false; |
| 173 | } |
| 174 | |
| 175 | $this->_children[$child->_id] = &$child; |
| 176 | |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Removes a Log instance from the list of children. |
| 182 | * |
| 183 | * @param object $child The Log instance to remove. |
| 184 | * |
| 185 | * @return boolean True if the Log instance was successfully removed. |
| 186 | * |
| 187 | * @access public |
| 188 | */ |
| 189 | function removeChild($child) |
| 190 | { |
| 191 | if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) { |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | unset($this->_children[$child->_id]); |
| 196 | |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | } |
Note: See TracBrowser
for help on using the browser.
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)