ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
composite.php
Go to the documentation of this file.
1 <?php
23 class 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 }