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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Fri Oct 25 15:15:23 2002 UTC (21 years, 10 months ago) by cvsjoko
Branch: MAIN
+ generic logging mechanism via PEAR::Log

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

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