119 function Log_mail($name, $ident =
'', $conf = array(),
122 $this->_id = md5(microtime());
123 $this->_recipients = $name;
124 $this->_ident = $ident;
127 if (!empty($conf[
'from'])) {
128 $this->_from = $conf[
'from'];
130 $this->_from = ini_get(
'sendmail_from');
133 if (!empty($conf[
'subject'])) {
134 $this->_subject = $conf[
'subject'];
137 if (!empty($conf[
'preamble'])) {
138 $this->_preamble = $conf[
'preamble'];
141 if (!empty($conf[
'lineFormat'])) {
142 $this->_lineFormat = str_replace(array_keys($this->_formatMap),
143 array_values($this->_formatMap),
144 $conf[
'lineFormat']);
147 if (!empty($conf[
'timeFormat'])) {
148 $this->_timeFormat = $conf[
'timeFormat'];
151 if (!empty($conf[
'mailBackend'])) {
152 $this->_mailBackend = $conf[
'mailBackend'];
155 if (!empty($conf[
'mailParams'])) {
156 $this->_mailParams = $conf[
'mailParams'];
160 register_shutdown_function(array(&$this,
'_Log_mail'));
181 if (!$this->_opened) {
182 if (!empty($this->_preamble)) {
183 $this->_message = $this->_preamble .
"\r\n\r\n";
185 $this->_opened =
true;
186 $_shouldSend =
false;
200 if ($this->_opened) {
201 if ($this->_shouldSend && !empty($this->_message)) {
202 if ($this->_mailBackend ===
'') {
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) {
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);
217 $res = $mailer->send($this->_recipients, $headers,
225 $this->_message =
'';
226 $this->_shouldSend =
false;
228 $this->_opened =
false;
231 return ($this->_opened ===
false);
248 return $this->
close();
263 function log($message, $priority = null)
266 if ($priority === null) {
276 if (!$this->_opened && !$this->
open()) {
284 $this->_message .= $this->
_format($this->_lineFormat,
285 strftime($this->_timeFormat),
286 $priority, $message) .
"\r\n";
287 $this->_shouldSend =
true;
290 $this->
_announce(array(
'priority' => $priority,
'message' => $message));
_announce($event)
Informs each registered observer instance that a new message has been logged.
Log_mail($name, $ident='', $conf=array(), $level=PEAR_LOG_DEBUG)
Constructs a new Log_mail object.
UPTO($priority)
Calculate the log mask for all priorities up to the given priority.
flush()
Flushes the log output by forcing the email message to be sent now.
& factory($driver, $params=array())
Provides an interface for generating Mail:: objects of various types.
log($message, $priority=null)
Writes $message to the currently open mail message.
close()
Closes the message, if it is open, and sends the mail.
_isMasked($priority)
Check if the given priority is included in the current level mask.
_extractMessage($message)
Returns the string representation of the message data.
_format($format, $timestamp, $priority, $message)
Produces a formatted log line based on a format string and a set of variables representing the curren...
open()
Starts a new mail message.
isError($data, $code=null)
Tell whether a value is a PEAR error.