ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
All Data Structures Namespaces Files Functions Variables Modules Pages
Log_mail Class Reference
+ Inheritance diagram for Log_mail:
+ Collaboration diagram for Log_mail:

Public Member Functions

 Log_mail ($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Constructs a new Log_mail object. More...
 
 _Log_mail ()
 Destructor. More...
 
 open ()
 Starts a new mail message. More...
 
 close ()
 Closes the message, if it is open, and sends the mail. More...
 
 flush ()
 Flushes the log output by forcing the email message to be sent now. More...
 
 log ($message, $priority=null)
 Writes $message to the currently open mail message. More...
 
- Public Member Functions inherited from Log
 _classExists ($class)
 Utility function which wraps PHP's class_exists() function to ensure consistent behavior between PHP versions 4 and 5. More...
 
factory ($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a concrete Log instance of type $handler. More...
 
singleton ($handler, $name='', $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
 Attempts to return a reference to a concrete Log instance of type $handler, only creating a new instance if no log instance with the same parameters currently exists. More...
 
 open ()
 Abstract implementation of the open() method. More...
 
 close ()
 Abstract implementation of the close() method. More...
 
 flush ()
 Abstract implementation of the flush() method. More...
 
 log ($message, $priority=null)
 Abstract implementation of the log() method. More...
 
 emerg ($message)
 A convenience function for logging a emergency event. More...
 
 alert ($message)
 A convenience function for logging an alert event. More...
 
 crit ($message)
 A convenience function for logging a critical event. More...
 
 err ($message)
 A convenience function for logging a error event. More...
 
 warning ($message)
 A convenience function for logging a warning event. More...
 
 notice ($message)
 A convenience function for logging a notice event. More...
 
 info ($message)
 A convenience function for logging a information event. More...
 
 debug ($message)
 A convenience function for logging a debug event. More...
 
 _extractMessage ($message)
 Returns the string representation of the message data. More...
 
 _getBacktraceVars ($depth)
 Using debug_backtrace(), returns the file, line, and enclosing function name of the source code context from which log() was invoked. More...
 
 _format ($format, $timestamp, $priority, $message)
 Produces a formatted log line based on a format string and a set of variables representing the current log record and state. More...
 
 priorityToString ($priority)
 Returns the string representation of a PEAR_LOG_* integer constant. More...
 
 stringToPriority ($name)
 Returns the the PEAR_LOG_* integer constant for the given string representation of a priority name. More...
 
 MASK ($priority)
 Calculate the log mask for the given priority. More...
 
 UPTO ($priority)
 Calculate the log mask for all priorities up to the given priority. More...
 
 MIN ($priority)
 Calculate the log mask for all priorities greater than or equal to the given priority. More...
 
 MAX ($priority)
 Calculate the log mask for all priorities less than or equal to the given priority. More...
 
 setMask ($mask)
 Set and return the level mask for the current Log instance. More...
 
 getMask ()
 Returns the current level mask. More...
 
 _isMasked ($priority)
 Check if the given priority is included in the current level mask. More...
 
 getPriority ()
 Returns the current default priority. More...
 
 setPriority ($priority)
 Sets the default priority to the specified value. More...
 
 attach (&$observer)
 Adds a Log_observer instance to the list of observers that are listening for messages emitted by this Log instance. More...
 
 detach ($observer)
 Removes a Log_observer instance from the list of observers. More...
 
 _announce ($event)
 Informs each registered observer instance that a new message has been logged. More...
 
 isComposite ()
 Indicates whether this is a composite class. More...
 
 setIdent ($ident)
 Sets this Log instance's identification string. More...
 
 getIdent ()
 Returns the current identification string. More...
 

Data Fields

 $_recipients = ''
 
 $_from = ''
 
 $_subject = '[Log_mail] Log message'
 
 $_preamble = ''
 
 $_lineFormat = '%1$s %2$s [%3$s] %4$s'
 
 $_timeFormat = '%b %d %H:%M:%S'
 
 $_message = ''
 
 $_shouldSend = false
 
 $_mailBackend = ''
 
 $_mailParams = array()
 
- Data Fields inherited from Log
 $_opened = false
 
 $_id = 0
 
 $_ident = ''
 
 $_priority = PEAR_LOG_INFO
 
 $_mask = PEAR_LOG_ALL
 
 $_listeners = array()
 
 $_formatMap
 

Detailed Description

Definition at line 28 of file mail.php.

Member Function Documentation

◆ _Log_mail()

Log_mail::_Log_mail ( )

Destructor.

Calls close().

private

Definition at line 168 of file mail.php.

References close().

169  {
170  $this->close();
171  }
close()
Closes the message, if it is open, and sends the mail.
Definition: mail.php:198
+ Here is the call graph for this function:

◆ close()

Log_mail::close ( )

Closes the message, if it is open, and sends the mail.

This is implicitly called by the destructor, if necessary.

public

Definition at line 198 of file mail.php.

References $res, Mail\factory(), and PEAR\isError().

Referenced by _Log_mail(), and flush().

199  {
200  if ($this->_opened) {
201  if ($this->_shouldSend && !empty($this->_message)) {
202  if ($this->_mailBackend === '') { // use mail()
203  $headers = "From: $this->_from\r\n";
204  $headers .= 'User-Agent: PEAR Log Package';
205  if (mail($this->_recipients, $this->_subject,
206  $this->_message, $headers) == false) {
207  return false;
208  }
209  } else { // use PEAR::Mail
210  include_once 'Mail.php';
211  $headers = array('From' => $this->_from,
212  'To' => $this->_recipients,
213  'User-Agent' => 'PEAR Log Package',
214  'Subject' => $this->_subject);
215  $mailer = &Mail::factory($this->_mailBackend,
216  $this->_mailParams);
217  $res = $mailer->send($this->_recipients, $headers,
218  $this->_message);
219  if (PEAR::isError($res)) {
220  return false;
221  }
222  }
223 
224  /* Clear the message string now that the email has been sent. */
225  $this->_message = '';
226  $this->_shouldSend = false;
227  }
228  $this->_opened = false;
229  }
230 
231  return ($this->_opened === false);
232  }
& factory($driver, $params=array())
Provides an interface for generating Mail:: objects of various types.
Definition: Mail.php:74
isError($data, $code=null)
Tell whether a value is a PEAR error.
Definition: PEAR.php:279
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flush()

Log_mail::flush ( )

Flushes the log output by forcing the email message to be sent now.

Events that are logged after flush() is called will be appended to a new email message.

public

Since
Log 1.8.2

Definition at line 242 of file mail.php.

References close().

243  {
244  /*
245  * It's sufficient to simply call close() to flush the output.
246  * The next call to log() will cause the handler to be reopened.
247  */
248  return $this->close();
249  }
close()
Closes the message, if it is open, and sends the mail.
Definition: mail.php:198
+ Here is the call graph for this function:

◆ log()

Log_mail::log (   $message,
  $priority = null 
)

Writes $message to the currently open mail message.

Calls open(), if necessary.

Parameters
mixed$messageString or object containing the message to log.
string$priorityThe priority of the message. Valid values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
Returns
boolean True on success or false on failure. public

Definition at line 263 of file mail.php.

References Log\$_priority, Log\_announce(), Log\_extractMessage(), Log\_format(), Log\_isMasked(), and open().

264  {
265  /* If a priority hasn't been specified, use the default value. */
266  if ($priority === null) {
267  $priority = $this->_priority;
268  }
269 
270  /* Abort early if the priority is above the maximum logging level. */
271  if (!$this->_isMasked($priority)) {
272  return false;
273  }
274 
275  /* If the message isn't open and can't be opened, return failure. */
276  if (!$this->_opened && !$this->open()) {
277  return false;
278  }
279 
280  /* Extract the string representation of the message. */
281  $message = $this->_extractMessage($message);
282 
283  /* Append the string containing the complete log line. */
284  $this->_message .= $this->_format($this->_lineFormat,
285  strftime($this->_timeFormat),
286  $priority, $message) . "\r\n";
287  $this->_shouldSend = true;
288 
289  /* Notify observers about this log message. */
290  $this->_announce(array('priority' => $priority, 'message' => $message));
291 
292  return true;
293  }
_announce($event)
Informs each registered observer instance that a new message has been logged.
Definition: Log.php:811
$_priority
Definition: Log.php:69
_isMasked($priority)
Check if the given priority is included in the current level mask.
Definition: Log.php:726
_extractMessage($message)
Returns the string representation of the message data.
Definition: Log.php:417
_format($format, $timestamp, $priority, $message)
Produces a formatted log line based on a format string and a set of variables representing the curren...
Definition: Log.php:530
open()
Starts a new mail message.
Definition: mail.php:179
+ Here is the call graph for this function:

◆ Log_mail()

Log_mail::Log_mail (   $name,
  $ident = '',
  $conf = array(),
  $level = PEAR_LOG_DEBUG 
)

Constructs a new Log_mail object.

Here is how you can customize the mail driver with the conf[] hash : $conf['from']: the mail's "From" header line, $conf['subject']: the mail's "Subject" line. $conf['mailBackend']: backend name of PEAR::Mail $conf['mailParams']: parameters for the PEAR::Mail backend

Parameters
string$nameThe message's recipients.
string$identThe identity string.
array$confThe configuration array.
int$levelLog messages up to and including this level. public

Definition at line 119 of file mail.php.

References Log\UPTO().

121  {
122  $this->_id = md5(microtime());
123  $this->_recipients = $name;
124  $this->_ident = $ident;
125  $this->_mask = Log::UPTO($level);
126 
127  if (!empty($conf['from'])) {
128  $this->_from = $conf['from'];
129  } else {
130  $this->_from = ini_get('sendmail_from');
131  }
132 
133  if (!empty($conf['subject'])) {
134  $this->_subject = $conf['subject'];
135  }
136 
137  if (!empty($conf['preamble'])) {
138  $this->_preamble = $conf['preamble'];
139  }
140 
141  if (!empty($conf['lineFormat'])) {
142  $this->_lineFormat = str_replace(array_keys($this->_formatMap),
143  array_values($this->_formatMap),
144  $conf['lineFormat']);
145  }
146 
147  if (!empty($conf['timeFormat'])) {
148  $this->_timeFormat = $conf['timeFormat'];
149  }
150 
151  if (!empty($conf['mailBackend'])) {
152  $this->_mailBackend = $conf['mailBackend'];
153  }
154 
155  if (!empty($conf['mailParams'])) {
156  $this->_mailParams = $conf['mailParams'];
157  }
158 
159  /* register the destructor */
160  register_shutdown_function(array(&$this, '_Log_mail'));
161  }
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
Definition: Log.php:642
+ Here is the call graph for this function:

◆ open()

Log_mail::open ( )

Starts a new mail message.

This is implicitly called by log(), if necessary.

public

Definition at line 179 of file mail.php.

References Log\$_opened.

Referenced by log().

180  {
181  if (!$this->_opened) {
182  if (!empty($this->_preamble)) {
183  $this->_message = $this->_preamble . "\r\n\r\n";
184  }
185  $this->_opened = true;
186  $_shouldSend = false;
187  }
188 
189  return $this->_opened;
190  }
$_shouldSend
Definition: mail.php:88
$_opened
Definition: Log.php:45
+ Here is the caller graph for this function:

Field Documentation

◆ $_from

Log_mail::$_from = ''

Definition at line 43 of file mail.php.

◆ $_lineFormat

Log_mail::$_lineFormat = '%1$s %2$s [%3$s] %4$s'

Definition at line 64 of file mail.php.

◆ $_mailBackend

Log_mail::$_mailBackend = ''

Definition at line 95 of file mail.php.

◆ $_mailParams

Log_mail::$_mailParams = array()

Definition at line 102 of file mail.php.

◆ $_message

Log_mail::$_message = ''

Definition at line 80 of file mail.php.

◆ $_preamble

Log_mail::$_preamble = ''

Definition at line 57 of file mail.php.

◆ $_recipients

Log_mail::$_recipients = ''

Definition at line 36 of file mail.php.

◆ $_shouldSend

Log_mail::$_shouldSend = false

Definition at line 88 of file mail.php.

◆ $_subject

Log_mail::$_subject = '[Log_mail] Log message'

Definition at line 50 of file mail.php.

◆ $_timeFormat

Log_mail::$_timeFormat = '%b %d %H:%M:%S'

Definition at line 73 of file mail.php.


The documentation for this class was generated from the following file: