ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
composite.php
Go to the documentation of this file.
1<?php
23class Log_composite extends Log
24{
32 var $_children = array();
33
34
45 function Log_composite($name, $ident = '', $conf = array(),
46 $level = PEAR_LOG_DEBUG)
47 {
48 $this->_ident = $ident;
49 }
50
58 function open()
59 {
60 /* Attempt to open each of our children. */
61 $this->_opened = true;
62 foreach ($this->_children as $id => $child) {
63 $this->_opened &= $this->_children[$id]->open();
64 }
65
66 /* If all children were opened, return success. */
67 return $this->_opened;
68 }
69
77 function close()
78 {
79 /* Attempt to close each of our children. */
80 $closed = true;
81 foreach ($this->_children as $id => $child) {
82 $closed &= $this->_children[$id]->close();
83 }
84
85 /* Track the _opened state for consistency. */
86 $this->_opened = false;
87
88 /* If all children were closed, return success. */
89 return $closed;
90 }
91
101 function flush()
102 {
103 /* Attempt to flush each of our children. */
104 $flushed = true;
105 foreach ($this->_children as $id => $child) {
106 $flushed &= $this->_children[$id]->flush();
107 }
108
109 /* If all children were flushed, return success. */
110 return $flushed;
111 }
112
130 function log($message, $priority = null)
131 {
132 /* If a priority hasn't been specified, use the default value. */
133 if ($priority === null) {
134 $priority = $this->_priority;
135 }
136
137 /*
138 * If the handlers haven't been opened, attempt to open them now.
139 * However, we don't treat failure to open all of the handlers as a
140 * fatal error. We defer that consideration to the success of calling
141 * each handler's log() method below.
142 */
143 if (!$this->_opened) {
144 $this->open();
145 }
146
147 /* Attempt to log the event using each of the children. */
148 $success = true;
149 foreach ($this->_children as $id => $child) {
150 $success &= $this->_children[$id]->log($message, $priority);
151 }
152
153 $this->_announce(array('priority' => $priority, 'message' => $message));
154
155 /* Return success if all of the children logged the event. */
156 return $success;
157 }
158
166 function isComposite()
167 {
168 return true;
169 }
170
179 function setIdent($ident)
180 {
181 /* Call our base class's setIdent() method. */
182 parent::setIdent($ident);
183
184 /* ... and then call setIdent() on all of our children. */
185 foreach ($this->_children as $id => $child) {
186 $this->_children[$id]->setIdent($ident);
187 }
188 }
189
199 function addChild(&$child)
200 {
201 /* Make sure this is a Log instance. */
202 if (!is_a($child, 'Log')) {
203 return false;
204 }
205
206 $this->_children[$child->_id] = &$child;
207
208 return true;
209 }
210
220 function removeChild($child)
221 {
222 if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) {
223 return false;
224 }
225
226 unset($this->_children[$child->_id]);
227
228 return true;
229 }
230
231}
const PEAR_LOG_DEBUG
Definition: Log.php:17
$success
Definition: Utf8Test.php:87
removeChild($child)
Removes a Log instance from the list of children.
Definition: composite.php:220
close()
Closes all of the child instances.
Definition: composite.php:77
log($message, $priority=null)
Sends $message and $priority to each child of this composite.
Definition: composite.php:130
addChild(&$child)
Adds a Log instance to the list of children.
Definition: composite.php:199
flush()
Flushes all child instances.
Definition: composite.php:101
Log_composite($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new composite Log object.
Definition: composite.php:45
open()
Opens all of the child instances.
Definition: composite.php:58
setIdent($ident)
Sets this identification string for all of this composite's children.
Definition: composite.php:179
isComposite()
Returns true if this is a composite.
Definition: composite.php:166
$_priority
Definition: Log.php:69
$_opened
Definition: Log.php:45
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
The Log:: class implements both an abstraction for various logging mechanisms and the Subject end of ...