/[cvs]/nfo/php/libs/net.php.pear/Log/composite.php
ViewVC logotype

Contents of /nfo/php/libs/net.php.pear/Log/composite.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Wed Feb 5 21:48:31 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +137 -129 lines
+ updated to Log-1.5.3

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed