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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by cvsjoko, Fri Oct 25 15:15:23 2002 UTC revision 1.2 by joko, Wed Feb 5 21:48:31 2003 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $  // $Id$
3    // $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $
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   * The Log_mcal class is a concrete implementation of the Log::
7   * store accessed through MCAL.   * abstract class which sends messages to a local or remote calendar
8   *   * store accessed through MCAL.
9   * @author  Chuck Hagenbuch <chuck@horde.org>   *
10   * @version $Revision$   * @author  Chuck Hagenbuch <chuck@horde.org>
11   * @since Horde 1.3   * @version $Revision$
12   */   * @since Horde 1.3
13  class Log_mcal extends Log {   * @package Log
14         */
15      // {{{ properties  class Log_mcal extends Log {
16        
17      /** String holding the calendar specification to connect to. */      /**
18      var $calendar = '{localhost/mstore}';      * holding the calendar specification to connect to.
19                * @var string
20          /** String holding the username to use. */      */
21          var $username = '';      var $_calendar = '{localhost/mstore}';
22            
23          /** String holding the password to use. */      /**
24          var $password = '';      * holding the username to use.
25                * @var string
26          /** Integer holding the options to pass to the calendar stream. */      */
27          var $options = 0;      var $_username = '';
28            
29      /** ResourceID of the MCAL stream. */      /**
30      var $stream = '';      * holding the password to use.
31                * @var string
32      /** Integer holding the log facility to use. */      */
33      var $name = LOG_SYSLOG;      var $_password = '';
34            
35      // }}}      /**
36            * holding the options to pass to the calendar stream.
37            * @var integer
38      // {{{ constructor      */
39      /**      var $_options = 0;
40       * Constructs a new Log_mcal object.  
41       *      /**
42       * @param $log_name (optional) The category to use for our events.      * ResourceID of the MCAL stream.
43       * @param $ident    (optional) The identity string.      * @var string
44       * @param $conf     (optional) The configuration array.      */
45       */      var $_stream = '';
46      function Log_mcal ($log_name = LOG_SYSLOG, $ident = '', $conf = false) {  
47          $this->name = $log_name;      /**
48          $this->ident = $ident;      * Integer holding the log facility to use.
49                  $this->calendar = $conf['calendar'];      * @var string
50                  $this->username = $conf['username'];      */
51                  $this->password = $conf['password'];      var $_name = LOG_SYSLOG;
52                  $this->options = $conf['options'];  
53      }  
54      // }}}      /**
55             * Constructs a new Log_mcal object.
56             *
57      // {{{ open()       * @param string $name     The category to use for our events.
58      /**       * @param string $ident    The identity string.
59       * Opens a calendar stream, if it has not already been       * @param array  $conf     The configuration array.
60       * opened. This is implicitly called by log(), if necessary.       * @param int    $maxLevel Maximum level at which to log.
61           */       * @access public
62      function open () {       */
63          if (!$this->opened) {      function Log_mcal($name, $ident = '', $conf = array(),
64              $this->stream = mcal_open($this->calendar, $this->username, $this->password, $this->options);                        $maxLevel = PEAR_LOG_DEBUG)
65              $this->opened = true;      {
66          }          $this->_name = $name;
67      }          $this->_ident = $ident;
68      // }}}          $this->_maxLevel = $maxLevel;
69                $this->_calendar = $conf['calendar'];
70      // {{{ close()          $this->_username = $conf['username'];
71      /**          $this->_password = $conf['password'];
72       * Closes the calendar stream, if it is open.          $this->_options = $conf['options'];
73       */      }
74      function close () {  
75          if ($this->opened) {      /**
76              mcal_close($this->stream);       * Opens a calendar stream, if it has not already been
77              $this->opened = false;       * opened. This is implicitly called by log(), if necessary.
78          }       * @access public
79      }       */
80      // }}}      function open()
81            {
82      // {{{ log()          if (!$this->_opened) {
83      /**              $this->_stream = mcal_open($this->_calendar, $this->_username,
84       * Logs $message and associated information to the currently open                  $this->_password, $this->_options);
85       * calendar stream. Calls open() if necessary. Also passes the              $this->_opened = true;
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       * Closes the calendar stream, if it is open.
91       *                  values are: LOG_EMERG, LOG_ALERT, LOG_CRIT,       * @access public
92       *                  LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO,       */
93       *                  and LOG_DEBUG. The default is LOG_INFO.      function close()
94           */      {
95      function log ($message, $priority = LOG_INFO) {          if ($this->_opened) {
96          if (!$this->opened)              mcal_close($this->_stream);
97              $this->open();              $this->_opened = false;
98                            }
99          $date_str = date('Y:n:j:G:i:s');      }
100                  $dates = explode(':', $date_str);  
101                        /**
102                  mcal_event_init($this->stream);       * Logs $message and associated information to the currently open
103                  mcal_event_set_title($this->stream, $this->ident);       * calendar stream. Calls open() if necessary. Also passes the
104                  mcal_event_set_category($this->stream, $this->name);       * message along to any Log_observer instances that are observing
105                  mcal_event_set_description($this->stream, $message);       * this Log.
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]);       * @param string $message  The textual message to be logged.
108                  mcal_event_set_end($this->stream, $dates[0], $dates[1], $dates[2], $dates[3], $dates[4], $dates[5]);       * @param string $priority The priority of the message. Valid
109                  mcal_append_event($this->stream);       *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
110                         *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
111          $this->notifyAll(array('priority' => $priority, 'message' => $message));       *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
112      }       *                  The default is PEAR_LOG_INFO.
113      // }}}       * @return boolean  True on success or false on failure.
114             * @access public
115  }       */
116        function log($message, $priority = PEAR_LOG_INFO)
117  ?>      {
118            /* Abort early if the priority is above the maximum logging level. */
119            if ($priority > $this->_maxLevel) {
120                return false;
121            }
122    
123            if (!$this->_opened) {
124                $this->open();
125            }
126    
127            $date_str = date('Y:n:j:G:i:s');
128            $dates = explode(':', $date_str);
129    
130            mcal_event_init($this->_stream);
131            mcal_event_set_title($this->_stream, $this->_ident);
132            mcal_event_set_category($this->_stream, $this->_name);
133            mcal_event_set_description($this->_stream, $message);
134            mcal_event_add_attribute($this->_stream, 'priority', $priority);
135            mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2],
136                $dates[3], $dates[4], $dates[5]);
137            mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2],
138                $dates[3], $dates[4], $dates[5]);
139            mcal_append_event($this->_stream);
140    
141            $this->notifyAll(array('priority' => $priority, 'message' => $message));
142    
143            return true;
144        }
145    }
146    
147    ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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