Created
October 10, 2012 07:05
-
-
Save komagata/3863627 to your computer and use it in GitHub Desktop.
Sending log by mail for CakePHP1.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* メールを送るロガー | |
* | |
* 使い方: | |
* // app/config/bootstrup.php: | |
* CakeLog::config('mailLog', array( | |
* 'engine' => 'MailLog', | |
* 'to' => '[email protected]', | |
* 'from' => '[email protected]' | |
* )); | |
*/ | |
class MailLog | |
{ | |
private $to; | |
private $from; | |
/** | |
* オプションを設定する | |
* | |
* @param array $options メールのto、fromの設定 | |
* @return void | |
*/ | |
public function __construct($options = array()) | |
{ | |
if (isset($options['to'])) { | |
$this->to = $options['to']; | |
} | |
if (isset($options['from'])) { | |
$this->from = $options['from']; | |
} | |
} | |
/** | |
* ログをメールで送る(ログを書く) | |
* | |
* @param string $type エラーの種類 | |
* @param string $message エラーの内容 | |
* @return void | |
*/ | |
public function write($type, $message) | |
{ | |
$subject = "[{$type}] ".mb_substr($message, 0, 32); | |
mb_send_mail($this->to, $subject, $message, "From: {$this->from}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment