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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 cvsjoko 1.1 <?php
2     // $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $
3    
4     /**
5     * The Log_mcal class is a concrete implementation of the Log::
6     * abstract class which sends messages to a local or remote calendar
7     * store accessed through MCAL.
8     *
9     * @author Chuck Hagenbuch <chuck@horde.org>
10     * @version $Revision: 1.1 $
11     * @since Horde 1.3
12     */
13     class Log_mcal extends Log {
14    
15     // {{{ properties
16    
17     /** String holding the calendar specification to connect to. */
18     var $calendar = '{localhost/mstore}';
19    
20     /** String holding the username to use. */
21     var $username = '';
22    
23     /** String holding the password to use. */
24     var $password = '';
25    
26     /** Integer holding the options to pass to the calendar stream. */
27     var $options = 0;
28    
29     /** ResourceID of the MCAL stream. */
30     var $stream = '';
31    
32     /** Integer holding the log facility to use. */
33     var $name = LOG_SYSLOG;
34    
35     // }}}
36    
37    
38     // {{{ constructor
39     /**
40     * Constructs a new Log_mcal object.
41     *
42     * @param $log_name (optional) The category to use for our events.
43     * @param $ident (optional) The identity string.
44     * @param $conf (optional) The configuration array.
45     */
46     function Log_mcal ($log_name = LOG_SYSLOG, $ident = '', $conf = false) {
47     $this->name = $log_name;
48     $this->ident = $ident;
49     $this->calendar = $conf['calendar'];
50     $this->username = $conf['username'];
51     $this->password = $conf['password'];
52     $this->options = $conf['options'];
53     }
54     // }}}
55    
56    
57     // {{{ open()
58     /**
59     * Opens a calendar stream, if it has not already been
60     * opened. This is implicitly called by log(), if necessary.
61     */
62     function open () {
63     if (!$this->opened) {
64     $this->stream = mcal_open($this->calendar, $this->username, $this->password, $this->options);
65     $this->opened = true;
66     }
67     }
68     // }}}
69    
70     // {{{ close()
71     /**
72     * Closes the calendar stream, if it is open.
73     */
74     function close () {
75     if ($this->opened) {
76     mcal_close($this->stream);
77     $this->opened = false;
78     }
79     }
80     // }}}
81    
82     // {{{ log()
83     /**
84     * Logs $message and associated information to the currently open
85     * calendar stream. Calls open() if necessary. Also passes the
86     * message along to any Log_observer instances that are observing
87     * this Log.
88     *
89     * @param $message The textual message to be logged.
90     * @param $priority (optional) The priority of the message. Valid
91     * values are: LOG_EMERG, LOG_ALERT, LOG_CRIT,
92     * LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO,
93     * and LOG_DEBUG. The default is LOG_INFO.
94     */
95     function log ($message, $priority = LOG_INFO) {
96     if (!$this->opened)
97     $this->open();
98    
99     $date_str = date('Y:n:j:G:i:s');
100     $dates = explode(':', $date_str);
101    
102     mcal_event_init($this->stream);
103     mcal_event_set_title($this->stream, $this->ident);
104     mcal_event_set_category($this->stream, $this->name);
105     mcal_event_set_description($this->stream, $message);
106     mcal_event_add_attribute($this->stream, 'priority', $priority);
107     mcal_event_set_start($this->stream, $dates[0], $dates[1], $dates[2], $dates[3], $dates[4], $dates[5]);
108     mcal_event_set_end($this->stream, $dates[0], $dates[1], $dates[2], $dates[3], $dates[4], $dates[5]);
109     mcal_append_event($this->stream);
110    
111     $this->notifyAll(array('priority' => $priority, 'message' => $message));
112     }
113     // }}}
114    
115     }
116    
117     ?>

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